From aada5273fa260cbd2441e8f1a0c95d951b4977fc Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 18 Jul 2017 01:18:20 +0800 Subject: 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 --- app/models/commit.rb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'app/models/commit.rb') 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: [] } -- cgit v1.2.1 From ffc5b29bd0f02676bdc05ec6185d115d6705cd8f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 18 Jul 2017 17:48:48 +0800 Subject: Follow feedback on the merge request --- app/models/commit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 337236b30d5..66c6ae4dacf 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -1,6 +1,6 @@ class Commit extend ActiveModel::Naming - extend Gitlab::Cache::RequestStoreWrap + extend Gitlab::Cache::RequestCache include ActiveModel::Conversion include Noteable -- cgit v1.2.1 From 3922b803290ecccdb232c2c150ee249ba2b57c97 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 18 Jul 2017 18:04:20 +0800 Subject: Rename the methods to make it fit with current name --- app/models/commit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 66c6ae4dacf..50790a710bb 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -172,7 +172,7 @@ class Commit def author User.find_by_any_email(author_email.downcase) end - request_store_wrap(:author) { author_email.downcase } + request_cache(:author) { author_email.downcase } def committer @committer ||= User.find_by_any_email(committer_email.downcase) -- cgit v1.2.1