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