summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-07-18 01:18:20 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-07-18 01:18:20 +0800
commitaada5273fa260cbd2441e8f1a0c95d951b4977fc (patch)
tree756f82f4492659adc61ee47f12b9c6a780cb5077 /app/models/commit.rb
parent143fc48abac6e278dcda9be4b90cb3ca1291f4d9 (diff)
downloadgitlab-ce-aada5273fa260cbd2441e8f1a0c95d951b4977fc.tar.gz
Use RequestStoreWrap for Commit#author
We also try to use instance variable to cache the result if RequestStore is not available, so we could keep the same logic, using the same cache key. Also introduce a way to specify method specific cache key
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb19
1 files changed, 3 insertions, 16 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index c7f62617c4c..337236b30d5 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -1,5 +1,6 @@
class Commit
extend ActiveModel::Naming
+ extend Gitlab::Cache::RequestStoreWrap
include ActiveModel::Conversion
include Noteable
@@ -169,19 +170,9 @@ class Commit
end
def author
- 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.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
+ User.find_by_any_email(author_email.downcase)
end
+ request_store_wrap(:author) { author_email.downcase }
def committer
@committer ||= User.find_by_any_email(committer_email.downcase)
@@ -368,10 +359,6 @@ class Commit
end
end
- def find_author_by_any_email
- User.find_by_any_email(author_email.downcase)
- end
-
def repo_changes
changes = { added: [], modified: [], removed: [] }