-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add commit count caching #2774
Add commit count caching #2774
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2774 +/- ##
==========================================
- Coverage 27.23% 27.21% -0.03%
==========================================
Files 88 88
Lines 17333 17348 +15
==========================================
Hits 4721 4721
- Misses 11927 11942 +15
Partials 685 685
Continue to review full report at Codecov.
|
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.
A few minor things
models/update.go
Outdated
if err != nil { | ||
return nil, fmt.Errorf("pushUpdateAddTag: %v", err) | ||
} | ||
} | ||
} else if !isDelRef { | ||
// If is branch reference | ||
|
||
// Clear cache for branch commit counr |
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.
typo: counr
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.
(forgot to include a comment)
modules/context/repo.go
Outdated
// GetCommitsCount returns cached commit count for current view | ||
func (r *Repository) GetCommitsCount() (int64, error) { | ||
if r.IsViewBranch { | ||
return cache.GetInt64(fmt.Sprintf("branch-commits-count-%d-%s", r.Repository.ID, r.BranchName), func() (int64, error) { |
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.
Could we add helper functions for these cache keys instead of having "magic" strings? e.g
func BranchCommitsCountKey(repoID int64, branchName string) string { ... }
With helper functions, we don't have to worry about mistyped strings, and it makes the code cleaner IMO
modules/context/repo.go
Outdated
// GetCommitsCount returns cached commit count for current view | ||
func (r *Repository) GetCommitsCount() (int64, error) { | ||
if r.IsViewBranch { | ||
return cache.GetInt64(fmt.Sprintf("branch-commits-count-%d-%s", r.Repository.ID, r.BranchName), func() (int64, error) { |
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.
To me it feels like this should be in the model instead. Because now we end up with some places having it cached, and other places direct access 😕
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.
@bkcsoft
Theoretically I can move it to model and make it less context dependant as branch and tag names can not be the with same name anyway
EDIT: I can't really move it to model as it is context dependent
8b0904d
to
02dba2e
Compare
@ethantkoenig fixed |
models/repo.go
Outdated
@@ -258,6 +258,11 @@ func (repo *Repository) APIFormat(mode AccessMode) *api.Repository { | |||
return repo.innerAPIFormat(mode, false) | |||
} | |||
|
|||
// GetCommitsCountCacheKey returns cache key used for commits count caching. | |||
func (repo *Repository) GetCommitsCountCacheKey(contextName string) string { |
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.
This naming scheme is ambiguous. Although branch names cannot conflict with tag names, commit names may conflict with either branch or tag names (i.e. if a branch/tag's name matches a commit's SHA).
I think we'll need multiple functions for each type (branch, tag, commit)
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.
We can't display it in repo page anyway but ok I'll add it back :)
02dba2e
to
a0234a3
Compare
@ethantkoenig done |
LGTM |
modules/setting/setting.go
Outdated
func newCacheService() { | ||
CacheAdapter = Cfg.Section("cache").Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}) | ||
switch CacheAdapter { | ||
sec := Cfg.Section("mailer") |
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.
Why mailer
not cache
?
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.
Ouch, good catch 👍
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.
I mean all the cache. If I have only serval repos on my private VPS. I maybe don't want to enable cache to spent the memory.
And the cache could be disabled? |
@lunny do you mean disabling all caching or only commit count caching? |
@lunny I can add option for that but does that mean also disabling go-macaron cache? I don't know if it is actually used currently |
Just to note - commits are cached for 1 hour and if not accessed in this time are removed from memory. It could possibly be better to add configurable cache time for each item |
a0234a3
to
faaf672
Compare
@lunny fixed and added option to change caching time or disable it (setting caching time to 0) |
LGTM |
* Add commit count caching * Small refactoring * Add different key prefix for refs and commits * Add configuratuion option to allow to change caching time or disable it
Especially on large repositories like linux kernel getting commit count from git takes more or less 7 seconds, so let's cache it as commit count is needed on every repository page load.
For linux kernel repository (more then 700K commits) it brings down repository page load time from 11.5 seconds to 3.3 seconds on my development machine.