perf: extend action c_u index to include created_unix for faster dashboard feeds - #38076
Merged
lafriks merged 6 commits intoJun 17, 2026
Merged
Conversation
…oard feeds The c_u index on the action table was defined as (user_id, is_deleted) without created_unix. The dashboard feed query filters by those two columns and then orders by created_unix DESC, so the database had to load and sort every matching row before it could return the first page of 20 — causing 27+ second queries on large action tables. Adds created_unix as the third column of the c_u index so the database can seek to (user_id, is_deleted) and walk created_unix in reverse order, stopping after 20 rows without a full sort. Assisted-by: Claude:claude-sonnet-4-6
c_u index to include created_unix for faster dashboard feedsc_u index to include created_unix for faster dashboard feeds
delvh
approved these changes
Jun 11, 2026
Member
|
What's the different between this index and |
Member
Author
|
Member
|
Please resolve the conflicts. |
…index-created-unix # Conflicts: # models/migrations/migrations.go # models/migrations/v1_27/v337.go
Member
Author
@lunny fixed |
wxiaoguang
removed their request for review
June 16, 2026 23:40
…index-created-unix # Conflicts: # models/migrations/migrations.go # models/migrations/v1_27/v338.go # models/migrations/v1_27/v338_test.go
Member
Author
|
@lunny ping |
lafriks
approved these changes
Jun 17, 2026
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jun 18, 2026
* 'main' of https://github.com/go-gitea/gitea: perf: extend action `c_u` index to include `created_unix` for faster dashboard feeds (go-gitea#38076) fix: Various security fixes (go-gitea#38103) docs: add development setup guide (go-gitea#37960) fix: Various sec fixes 2 (go-gitea#38108)
ZPascal
pushed a commit
to ZPascal/gitea
that referenced
this pull request
Jun 18, 2026
…dashboard feeds (go-gitea#38076) Adds `created_unix` as the third column of the `c_u` composite index on the `action` table, changing it from `(user_id, is_deleted)` to `(user_id, is_deleted, created_unix)`. Migration 337 drops and recreates the index. No data is touched. defined it as `(user_id, is_deleted)` — without `created_unix`. actually use `c_u`, but because `created_unix` is absent from the index, the database must load and sort **every** matching row before returning the first page of 20. The existing `c_u_d` index `(created_unix, user_id, is_deleted)` does not help because its leading column is `created_unix`, which can't be used for an equality seek on `user_id`. Those two caused this issue: go-gitea#38075 With the fix, the database seeks directly to `(user_id=X, is_deleted=false)` and walks `created_unix` in descending order, stopping after 20 rows. Fixes go-gitea#38075
zeekay
pushed a commit
to hanzoai/git
that referenced
this pull request
Jul 26, 2026
…dashboard feeds (go-gitea#38076) Adds `created_unix` as the third column of the `c_u` composite index on the `action` table, changing it from `(user_id, is_deleted)` to `(user_id, is_deleted, created_unix)`. Migration 337 drops and recreates the index. No data is touched. ## Root causes go-gitea#32333 introduced the `c_u` index to speed up dashboard queries, but defined it as `(user_id, is_deleted)` — without `created_unix`. go-gitea#3368 The simple query is now efficient enough for the database to actually use `c_u`, but because `created_unix` is absent from the index, the database must load and sort **every** matching row before returning the first page of 20. The existing `c_u_d` index `(created_unix, user_id, is_deleted)` does not help because its leading column is `created_unix`, which can't be used for an equality seek on `user_id`. Those two caused this issue: go-gitea#38075 With the fix, the database seeks directly to `(user_id=X, is_deleted=false)` and walks `created_unix` in descending order, stopping after 20 rows. Fixes go-gitea#38075
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
created_unixas the third column of thec_ucomposite index on theactiontable, changing it from(user_id, is_deleted)to(user_id, is_deleted, created_unix).Migration 337 drops and recreates the index. No data is touched.
Root causes
#32333 introduced the
c_uindex to speed up dashboard queries, but defined it as(user_id, is_deleted)— withoutcreated_unix.#3368 The simple query is now efficient enough for the database to actually use
c_u, but becausecreated_unixis absent from the index, the database must load and sort every matching row before returning the first page of 20.The existing
c_u_dindex(created_unix, user_id, is_deleted)does not help because its leading column iscreated_unix, which can't be used for an equality seek onuser_id.Those two caused this issue: #38075
With the fix, the database seeks directly to
(user_id=X, is_deleted=false)and walkscreated_unixin descending order, stopping after 20 rows.Fixes #38075