From ba9f1b618937c8a03325709942130b0654a36d98 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sun, 5 Nov 2023 17:08:24 +0100 Subject: [PATCH] Memoize `commits` in `Page::AuthorsComponent` --- app/components/page/authors_component.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/components/page/authors_component.rb b/app/components/page/authors_component.rb index 704802bc..f519cf03 100644 --- a/app/components/page/authors_component.rb +++ b/app/components/page/authors_component.rb @@ -12,21 +12,21 @@ def git end def commits - @paths.flat_map { |path| git.gblob(path).log.to_a }.sort_by(&:author_date) - end - - def page_authors - commits.map(&:author).map { |a| [a.name, a.email] }.tally.keys - rescue => e - puts e - [] + @commits ||= @paths.flat_map { |path| git.gblob(path).log.to_a }.sort_by(&:author_date) end def last_commit - commits.last + @last_commit ||= commits.last end def last_commit_date last_commit.try(:author_date) end + + def page_authors + commits.map(&:author).map { |a| [a.name, a.email] }.tally.keys + rescue => e + puts e + [] + end end