blob: 37abad8130560e11ea1af3c10c12b5cf51011ae3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# frozen_string_literal: true
module Gitlab
module Diff
module FileCollection
# Builds a traditional paginated diff file collection using Kaminari
# `per` and `per_page` which is different from how `MergeRequestDiffBatch`
# works (e.g. supports gradual loading).
class PaginatedMergeRequestDiff < MergeRequestDiffBase
include PaginatedDiffs
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 30
delegate :limit_value, :current_page, :next_page, :prev_page, :total_count,
:total_pages, to: :paginated_collection
def initialize(merge_request_diff, page, per_page)
super(merge_request_diff, diff_options: nil)
@paginated_collection = load_paginated_collection(page, per_page)
end
private
def load_paginated_collection(page, per_page)
page ||= DEFAULT_PAGE
per_page ||= DEFAULT_PER_PAGE
relation.page(page).per([per_page.to_i, DEFAULT_PER_PAGE].min)
end
end
end
end
end
|