diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-03-05 10:37:16 +0100 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-03-06 14:32:53 +0100 |
commit | 1e08d00032c1160202567dacdf24c3b47458d86c (patch) | |
tree | db0bc6a4b29300575fea1bc7d5108f629909f4c9 /app/models/commit.rb | |
parent | b8aa65d47cea9c5db27e04f21d0ce5ca818a8c67 (diff) | |
download | gitlab-ce-1e08d00032c1160202567dacdf24c3b47458d86c.tar.gz |
Lazy fetch parent commits for a commit
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index b9106309142..cceae5efb72 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -9,6 +9,7 @@ class Commit include Mentionable include Referable include StaticModel + include ::Gitlab::Utils::StrongMemoize attr_mentionable :safe_message, pipeline: :single_line @@ -225,11 +226,13 @@ class Commit end def parents - @parents ||= parent_ids.map { |id| project.commit(id) } + @parents ||= parent_ids.map { |oid| Commit.lazy(project, oid) } end def parent - @parent ||= project.commit(self.parent_id) if self.parent_id + strong_memoize(:parent) do + project.commit_by(oid: self.parent_id) if self.parent_id + end end def notes |