diff options
Diffstat (limited to 'lib/gitlab/diff/file_collection/merge_request_diff_batch.rb')
-rw-r--r-- | lib/gitlab/diff/file_collection/merge_request_diff_batch.rb | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/gitlab/diff/file_collection/merge_request_diff_batch.rb b/lib/gitlab/diff/file_collection/merge_request_diff_batch.rb index 64523f3b730..5ff7c88970c 100644 --- a/lib/gitlab/diff/file_collection/merge_request_diff_batch.rb +++ b/lib/gitlab/diff/file_collection/merge_request_diff_batch.rb @@ -21,9 +21,9 @@ module Gitlab @paginated_collection = load_paginated_collection(batch_page, batch_size, diff_options) @pagination_data = { - current_page: batch_gradual_load? ? nil : @paginated_collection.current_page, - next_page: batch_gradual_load? ? nil : @paginated_collection.next_page, - total_pages: batch_gradual_load? ? relation.size : @paginated_collection.total_pages + current_page: current_page, + next_page: next_page, + total_pages: total_pages } end @@ -62,6 +62,24 @@ module Gitlab @merge_request_diff.merge_request_diff_files end + def current_page + return if @paginated_collection.blank? + + batch_gradual_load? ? nil : @paginated_collection.current_page + end + + def next_page + return if @paginated_collection.blank? + + batch_gradual_load? ? nil : @paginated_collection.next_page + end + + def total_pages + return if @paginated_collection.blank? + + batch_gradual_load? ? relation.size : @paginated_collection.total_pages + end + # rubocop: disable CodeReuse/ActiveRecord def load_paginated_collection(batch_page, batch_size, diff_options) batch_page ||= DEFAULT_BATCH_PAGE |