diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-07-29 11:58:48 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-07-29 11:58:48 +0300 |
commit | 9b0e131b83cfc44d3132bddfefb6cbd4bff7d253 (patch) | |
tree | 6a465888a9ce47f7f0306f367082cbe23d283a6b /app | |
parent | 5161983bd0c07fe8ffdc63f00c90d28895171294 (diff) | |
parent | d27e36f35af0c2850c5370a3348d30ce4bcf1a68 (diff) |
Merge branch 'cache-commit-author-lookup' into 'master'
Cache the commit author in RequestStore to avoid extra lookups in PostReceive
See merge request !5537
Diffstat (limited to 'app')
-rw-r--r-- | app/models/commit.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index f80f1063406..486ad6714d9 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -178,7 +178,18 @@ class Commit end def author - @author ||= User.find_by_any_email(author_email.downcase) + if RequestStore.active? + key = "commit_author:#{author_email.downcase}" + # nil is a valid value since no author may exist in the system + if RequestStore.store.has_key?(key) + @author = RequestStore.store[key] + else + @author = find_author_by_any_email + RequestStore.store[key] = @author + end + else + @author ||= find_author_by_any_email + end end def committer @@ -306,6 +317,10 @@ class Commit private + def find_author_by_any_email + User.find_by_any_email(author_email.downcase) + end + def repo_changes changes = { added: [], modified: [], removed: [] } |