Commit 6bcdd262 authored by Aleksei Lipniagov's avatar Aleksei Lipniagov

Enable pagination in the CompareController

Previously, the pagination in the Projects::CompareController was
disabled by default. It lead to the memory usage bloat. We enable it and
set it to a rather aggresive (low) value, unlike it was in the
CommitsController previously.
parent 413a6a8e
...@@ -26,6 +26,8 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -26,6 +26,8 @@ class Projects::CompareController < Projects::ApplicationController
feature_category :source_code_management feature_category :source_code_management
COMMIT_DIFFS_PER_PAGE = 10
def index def index
end end
......
...@@ -128,7 +128,7 @@ module CommitsHelper ...@@ -128,7 +128,7 @@ module CommitsHelper
%w(btn gpg-status-box) + Array(additional_classes) %w(btn gpg-status-box) + Array(additional_classes)
end end
def conditionally_paginate_diff_files(diffs, paginate:, per: Projects::CommitController::COMMIT_DIFFS_PER_PAGE) def conditionally_paginate_diff_files(diffs, paginate:, per:)
if paginate if paginate
Kaminari.paginate_array(diffs.diff_files.to_a).page(params[:page]).per(per) Kaminari.paginate_array(diffs.diff_files.to_a).page(params[:page]).per(per)
else else
......
...@@ -12,7 +12,12 @@ ...@@ -12,7 +12,12 @@
.container-fluid{ class: [limited_container_width, container_class] } .container-fluid{ class: [limited_container_width, container_class] }
= render "commit_box" = render "commit_box"
= render "ci_menu" = render "ci_menu"
= render "projects/diffs/diffs", diffs: @diffs, environment: @environment, diff_page_context: "is-commit", paginate_diffs: true = render "projects/diffs/diffs",
diffs: @diffs,
environment: @environment,
diff_page_context: "is-commit",
paginate_diffs: true,
paginate_diffs_per_page: Projects::CommitController::COMMIT_DIFFS_PER_PAGE
.limited-width-notes .limited-width-notes
= render "shared/notes/notes_with_form", :autocomplete => true = render "shared/notes/notes_with_form", :autocomplete => true
......
...@@ -7,7 +7,12 @@ ...@@ -7,7 +7,12 @@
- if @commits.present? - if @commits.present?
= render "projects/commits/commit_list" = render "projects/commits/commit_list"
= render "projects/diffs/diffs", diffs: @diffs, environment: @environment, diff_page_context: "is-compare" = render "projects/diffs/diffs",
diffs: @diffs,
environment: @environment,
diff_page_context: "is-compare",
paginate_diffs: true,
paginate_diffs_per_page: Projects::CompareController::COMMIT_DIFFS_PER_PAGE
- else - else
.card.bg-light .card.bg-light
.center .center
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
- diff_page_context = local_assigns.fetch(:diff_page_context, nil) - diff_page_context = local_assigns.fetch(:diff_page_context, nil)
- load_diff_files_async = Feature.enabled?(:async_commit_diff_files, @project) && diff_page_context == "is-commit" - load_diff_files_async = Feature.enabled?(:async_commit_diff_files, @project) && diff_page_context == "is-commit"
- paginate_diffs = local_assigns.fetch(:paginate_diffs, false) && !load_diff_files_async - paginate_diffs = local_assigns.fetch(:paginate_diffs, false) && !load_diff_files_async
- diff_files = conditionally_paginate_diff_files(diffs, paginate: paginate_diffs) - paginate_diffs_per_page = local_assigns.fetch(:paginate_diffs_per_page, nil)
- diff_files = conditionally_paginate_diff_files(diffs, paginate: paginate_diffs, per: paginate_diffs_per_page)
.content-block.oneline-block.files-changed.diff-files-changed.js-diff-files-changed .content-block.oneline-block.files-changed.diff-files-changed.js-diff-files-changed
.files-changed-inner .files-changed-inner
......
---
title: Enable pagination in the CompareController
merge_request: 59162
author:
type: performance
...@@ -144,7 +144,7 @@ RSpec.describe CommitsHelper do ...@@ -144,7 +144,7 @@ RSpec.describe CommitsHelper do
} }
end end
subject { helper.conditionally_paginate_diff_files(diffs_collection, paginate: paginate) } subject { helper.conditionally_paginate_diff_files(diffs_collection, paginate: paginate, per: Projects::CommitController::COMMIT_DIFFS_PER_PAGE) }
before do before do
allow(helper).to receive(:params).and_return(params) allow(helper).to receive(:params).and_return(params)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment