diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-09 21:07:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-09 21:07:50 +0300 |
commit | 20f6a17ba2d2d5f056bda38dfe85e2a7b2a82d0b (patch) | |
tree | 1319f393750fa7a212455746273c05465d786fde /app/models/merge_request_diff.rb | |
parent | e38a99eb0725697297386dd0bb1045b1fd55493a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/merge_request_diff.rb')
-rw-r--r-- | app/models/merge_request_diff.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 9f7e98dc04b..98a9ccc2040 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -292,9 +292,9 @@ class MergeRequestDiff < ApplicationRecord end end - def commits(limit: nil, load_from_gitaly: false) - strong_memoize(:"commits_#{limit || 'all'}_#{load_from_gitaly}") do - load_commits(limit: limit, load_from_gitaly: load_from_gitaly) + def commits(limit: nil, load_from_gitaly: false, page: nil) + strong_memoize(:"commits_#{limit || 'all'}_#{load_from_gitaly}_page_#{page}") do + load_commits(limit: limit, load_from_gitaly: load_from_gitaly, page: page) end end @@ -725,17 +725,19 @@ class MergeRequestDiff < ApplicationRecord end end - def load_commits(limit: nil, load_from_gitaly: false) + def load_commits(limit: nil, load_from_gitaly: false, page: nil) + diff_commits = page.present? ? merge_request_diff_commits.page(page).per(limit) : merge_request_diff_commits.limit(limit) + if load_from_gitaly - commits = Gitlab::Git::Commit.batch_by_oid(repository, merge_request_diff_commits.limit(limit).map(&:sha)) + commits = Gitlab::Git::Commit.batch_by_oid(repository, diff_commits.map(&:sha)) commits = Commit.decorate(commits, project) else - commits = merge_request_diff_commits.with_users.limit(limit) + commits = diff_commits.with_users .map { |commit| Commit.from_hash(commit.to_hash, project) } end CommitCollection - .new(merge_request.target_project, commits, merge_request.target_branch) + .new(merge_request.target_project, commits, merge_request.target_branch, page: page.to_i, per_page: limit, count: commits_count) end def save_diffs |