diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /lib/api/commits.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'lib/api/commits.rb')
-rw-r--r-- | lib/api/commits.rb | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 20877fb5c5f..3097bcc0ef1 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -62,19 +62,29 @@ module API first_parent: first_parent, order: order) - commit_count = - if all || path || before || after || first_parent - user_project.repository.count_commits(ref: ref, path: path, before: before, after: after, all: all, first_parent: first_parent) - else - # Cacheable commit count. - user_project.repository.commit_count_for_ref(ref) - end + serializer = with_stats ? Entities::CommitWithStats : Entities::Commit - paginated_commits = Kaminari.paginate_array(commits, total_count: commit_count) + if Feature.enabled?(:api_commits_without_count, user_project) + # This tells kaminari that there is 1 more commit after the one we've + # loaded, meaning there will be a next page, if the currently loaded set + # of commits is equal to the requested page size. + commit_count = offset + commits.size + 1 + paginated_commits = Kaminari.paginate_array(commits, total_count: commit_count) - serializer = with_stats ? Entities::CommitWithStats : Entities::Commit + present paginate(paginated_commits, exclude_total_headers: true), with: serializer + else + commit_count = + if all || path || before || after || first_parent + user_project.repository.count_commits(ref: ref, path: path, before: before, after: after, all: all, first_parent: first_parent) + else + # Cacheable commit count. + user_project.repository.commit_count_for_ref(ref) + end - present paginate(paginated_commits), with: serializer + paginated_commits = Kaminari.paginate_array(commits, total_count: commit_count) + + present paginate(paginated_commits), with: serializer + end end desc 'Commit multiple file changes as one commit' do |