Commit 1f2c3ba5 authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch '333875-remove-unused-pagination-data-from-diff_batch' into 'master'

Remove unused pagination data from diff_batch

See merge request gitlab-org/gitlab!64482
parents 299b32fd d6b7b0d0
......@@ -23,36 +23,13 @@ class PaginatedDiffEntity < Grape::Entity
end
expose :pagination do
expose :current_page
expose :next_page
expose :total_pages
expose :next_page_href do |diffs|
next unless next_page
project = merge_request.target_project
diffs_batch_namespace_project_json_merge_request_path(
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
page: next_page,
format: :json
)
expose :total_pages do |diffs, options|
options.dig(:pagination_data, :total_pages)
end
end
private
%i[current_page next_page total_pages].each do |method|
define_method method do
pagination_data[method]
end
end
def pagination_data
options.fetch(:pagination_data, {})
end
def merge_request
options[:merge_request]
end
......
......@@ -88,11 +88,7 @@ module Gitlab
private
def empty_pagination_data
{
current_page: nil,
next_page: nil,
total_pages: nil
}
{ total_pages: nil }
end
def diff_stats_collection
......
......@@ -21,8 +21,6 @@ module Gitlab
@paginated_collection = load_paginated_collection(batch_page, batch_size, diff_options)
@pagination_data = {
current_page: nil,
next_page: nil,
total_pages: @paginated_collection.blank? ? nil : relation.size
}
end
......
......@@ -472,8 +472,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do
diff_view: :inline,
merge_ref_head_diff: nil,
pagination_data: {
current_page: nil,
next_page: nil,
total_pages: nil
}.merge(pagination_data)
}
......@@ -515,7 +513,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) { collection_arguments(current_page: nil, total_pages: 20).merge(merge_ref_head_diff: false) }
let(:expected_options) { collection_arguments(total_pages: 20).merge(merge_ref_head_diff: false) }
end
it_behaves_like 'successful request'
......@@ -555,7 +553,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) do
collection_arguments(current_page: nil, total_pages: 20)
collection_arguments(total_pages: 20)
end
end
......@@ -574,7 +572,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) { collection_arguments(current_page: nil, total_pages: 20) }
let(:expected_options) { collection_arguments(total_pages: 20) }
end
it_behaves_like 'successful request'
......@@ -585,7 +583,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) { collection_arguments(current_page: nil, next_page: nil, total_pages: 20) }
let(:expected_options) { collection_arguments(total_pages: 20) }
end
it_behaves_like 'successful request'
......
......@@ -12,10 +12,7 @@ export default (server) => {
return {
...result,
pagination: withValues(pagination, {
current_page: null,
next_page: null,
total_pages: 1,
next_page_href: null,
}),
};
});
......
......@@ -20,7 +20,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
describe 'initialize' do
it 'memoizes pagination_data' do
expect(subject.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: 20)
expect(subject.pagination_data).to eq(total_pages: 20)
end
end
......
......@@ -432,9 +432,7 @@ RSpec.describe MergeRequestDiff do
it 'returns empty pagination data' do
diffs = diff_with_commits.diffs_in_batch(1, 10, diff_options: diff_options)
expect(diffs.pagination_data).to eq(current_page: nil,
next_page: nil,
total_pages: nil)
expect(diffs.pagination_data).to eq(total_pages: nil)
end
end
......@@ -460,9 +458,7 @@ RSpec.describe MergeRequestDiff do
expect(diffs).to be_a(Gitlab::Diff::FileCollection::MergeRequestDiffBatch)
expect(diffs.diff_files.size).to eq(10)
expect(diffs.pagination_data).to eq(current_page: nil,
next_page: nil,
total_pages: 20)
expect(diffs.pagination_data).to eq(total_pages: 20)
end
it 'sorts diff files directory first' do
......@@ -493,7 +489,7 @@ RSpec.describe MergeRequestDiff do
expect(diffs).to be_a(Gitlab::Diff::FileCollection::Compare)
expect(diffs.diff_files.size).to eq 10
expect(diffs.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: file_count)
expect(diffs.pagination_data).to eq(total_pages: file_count)
end
it 'returns an empty MergeRequestBatch with empty pagination data when the batch is empty' do
......@@ -501,7 +497,7 @@ RSpec.describe MergeRequestDiff do
expect(diffs).to be_a(Gitlab::Diff::FileCollection::MergeRequestDiffBatch)
expect(diffs.diff_files.size).to eq 0
expect(diffs.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: nil)
expect(diffs.pagination_data).to eq(total_pages: nil)
end
end
end
......
......@@ -24,12 +24,7 @@ RSpec.describe PaginatedDiffEntity do
end
it 'exposes pagination data' do
expect(subject[:pagination]).to eq(
current_page: nil,
next_page: nil,
next_page_href: nil,
total_pages: 20
)
expect(subject[:pagination]).to eq(total_pages: 20)
end
context 'when there are conflicts' do
......
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