From 8a9fc2b67e5bb6aeabdffa1f91115ac7613a505a Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 27 Jul 2016 15:35:53 -0700 Subject: Cache the commit author in RequestStore to avoid extra lookups in PostReceive In a PostReceive task with 697 commits (8.9 RC1 -> RC8), looking up the commit author takes about 10% of the time. Caching this information in RequestStore saves a few seconds from the overall processing time. Improves #18663 --- app/models/commit.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index f80f1063406..6a0d32d406e 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -178,7 +178,14 @@ class Commit end def author - @author ||= User.find_by_any_email(author_email.downcase) + 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) + end + + @author ||= RequestStore.store[key] end def committer -- cgit v1.2.1