diff options
author | Sean McGivern <sean@gitlab.com> | 2019-03-26 09:22:14 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-03-26 09:22:14 +0000 |
commit | 2ce68fd3a5a286cc5a1c438431df905a532d03fc (patch) | |
tree | 502603b16290f0d494cb3057f71add3bff685677 /app | |
parent | 849eb7c6e246b103a6837b969bb2a46aad9065e7 (diff) | |
parent | 541a55c934103647c39e33b71da9ff4ab3aada87 (diff) | |
download | gitlab-ce-2ce68fd3a5a286cc5a1c438431df905a532d03fc.tar.gz |
Merge branch '58805-allow-incomplete-commit-data-to-be-fetched-from-collection' into 'master'
Enrich commits with full data in CommitCollection
Closes #58805
See merge request gitlab-org/gitlab-ce!26445
Diffstat (limited to 'app')
-rw-r--r-- | app/models/commit_collection.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/app/models/commit_collection.rb b/app/models/commit_collection.rb index a9a2e9c81eb..52524456439 100644 --- a/app/models/commit_collection.rb +++ b/app/models/commit_collection.rb @@ -28,10 +28,43 @@ class CommitCollection def without_merge_commits strong_memoize(:without_merge_commits) do - commits.reject(&:merge_commit?) + # `#enrich!` the collection to ensure all commits contain + # the necessary parent data + enrich!.commits.reject(&:merge_commit?) end end + def unenriched + commits.reject(&:gitaly_commit?) + end + + def fully_enriched? + unenriched.empty? + end + + # Batch load any commits that are not backed by full gitaly data, and + # replace them in the collection. + def enrich! + # A project is needed in order to fetch data from gitaly. Projects + # can be absent from commits in certain rare situations (like when + # viewing a MR of a deleted fork). In these cases, assume that the + # enriched data is not needed. + return self if project.blank? || fully_enriched? + + # Batch load full Commits from the repository + # and map to a Hash of id => Commit + replacements = Hash[unenriched.map do |c| + [c.id, Commit.lazy(project, c.id)] + end.compact] + + # Replace the commits, keeping the same order + @commits = @commits.map do |c| + replacements.fetch(c.id, c) + end + + self + end + # Sets the pipeline status for every commit. # # Setting this status ahead of time removes the need for running a query for |