From d27e36f35af0c2850c5370a3348d30ce4bcf1a68 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 27 Jul 2016 16:42:38 -0700 Subject: Add specs for caching commit author --- app/models/commit.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 6a0d32d406e..486ad6714d9 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -178,14 +178,18 @@ class Commit end def author - key = "commit_author:#{author_email}" - - # nil is a valid value since no author may exist in the system - unless RequestStore.store.has_key?(key) - RequestStore.store[key] = 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 - - @author ||= RequestStore.store[key] end def committer @@ -313,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: [] } -- cgit v1.2.1