-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Storing branch commits count in db rather than caching them in memory or redis #33954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Storing branch commits count in db rather than caching them in memory or redis #33954
Conversation
modules/gitrepo/commit.go
Outdated
return nil, err | ||
} | ||
defer gitRepo.Close() | ||
return gitRepo.GetCommit(commitID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can not do this! You can not close the gitRepo then then access the returned "commit"!!!!
That's I said many times: I do not see how you could make the "gitrepo" package work correctly, but introducing more bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
998f9ff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really questionable whether it should be that complex
The whole design is problematic. You shouldn't make the logic tightly depending on each other. What you need is a "commit count cache" module.
You should make the module work for all branches, tags and commits. No more hacky patch please. |
@@ -84,6 +84,18 @@ func RefNameFromCommit(shortName string) RefName { | |||
return RefName(shortName) | |||
} | |||
|
|||
func RefNameFromRefTypeAndShortName(refType RefType, shortName string) RefName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should never need it.
Why you know "RefType" but don't know the full "RefName" when using the ref?
This cannot work well. For the first visit to a repository home page, it needs the commits count to decide whether last commit cache should be enabled at the moment. Except we cache all last commit information even there is less commits. Tag's commit count has already been stored in the database. |
I do not see the "last commit cache" is right either. |
The last commit cache isn’t perfect yet, but it has already improved homepage loading times — except on the first visit. |
Why not make it overall right first? Why it should depend on the commit count since it is stored in |
Branch commit counts are cached in memory or Redis after the first access. However, the initial page load is still slow because the commit count needs to be computed.
This PR introduces a new field in the database to store commit counts for branches. The commit count is updated automatically when branches are pushed or mirrored. Additionally, a background task periodically checks and corrects any discrepancies in the commit count to handle unexpected situations.
With this change, even if the commit count is not updated in time, a number will still be displayed in the UI. This prevents the UI from blocking the user, as commit counts are generally not critical for the user’s experience when visiting the page.
Note: The
release
table has a columnnum_commits
which stored the commit count of a tag. So that we just need to cache a commit's commit count in the cache.