Skip to content

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

lunny
Copy link
Member

@lunny lunny commented Mar 20, 2025

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 column num_commits which stored the commit count of a tag. So that we just need to cache a commit's commit count in the cache.

lunny added 6 commits March 20, 2025 15:51
Fix

Verified

This commit was signed with the committer’s verified signature.
lunny Lunny Xiao

Verified

This commit was signed with the committer’s verified signature.
lunny Lunny Xiao
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 20, 2025
@github-actions github-actions bot added modifies/translation modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/migrations labels Mar 20, 2025

Verified

This commit was signed with the committer’s verified signature.
lunny Lunny Xiao
return nil, err
}
defer gitRepo.Close()
return gitRepo.GetCommit(commitID)
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

998f9ff

Copy link
Contributor

@wxiaoguang wxiaoguang left a 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

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 21, 2025
lunny added 3 commits March 22, 2025 17:23

Verified

This commit was signed with the committer’s verified signature.
lunny Lunny Xiao
lunny added 2 commits April 28, 2025 19:58

Verified

This commit was signed with the committer’s verified signature.
lunny Lunny Xiao
@github-actions github-actions bot removed the modifies/api This PR adds API routes or modifies them label Apr 29, 2025
@wxiaoguang
Copy link
Contributor

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.

  • If the commit count is in cache: use it to render the template
  • If the commit count is not in cache: render a "loading" indicator and use async fetch to partially load the page, and start a background task to fill the commit count into cache.

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 {
Copy link
Contributor

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?

@lunny
Copy link
Member Author

lunny commented Apr 29, 2025

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.

  • If the commit count is in cache: use it to render the template
  • If the commit count is not in cache: render a "loading" indicator and use async fetch to partially load the page, and start a background task to fill the commit count into cache.

You should make the module work for all branches, tags and commits. No more hacky patch please.

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.

@wxiaoguang
Copy link
Contributor

whether last commit cache should be enabled at the moment.

I do not see the "last commit cache" is right either.

@lunny
Copy link
Member Author

lunny commented Apr 29, 2025

whether last commit cache should be enabled at the moment.

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.
Found a problem? Feel free to open an issue!

@wxiaoguang
Copy link
Contributor

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 git.Repository which is a per-request object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged modifies/go Pull requests that update Go code modifies/migrations modifies/translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants