Module: Gitlab::Diff::FileCollection::PaginatedDiffs

Extended by:
Utils::Override
Includes:
Utils::StrongMemoize
Included in:
MergeRequestDiffBatch, PaginatedMergeRequestDiff
Defined in:
lib/gitlab/diff/file_collection/paginated_diffs.rb

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Instance Method Details

#diffsObject



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
# File 'lib/gitlab/diff/file_collection/paginated_diffs.rb', line 11

def diffs
  merge_request_diff.opening_external_diff do
    # Avoiding any extra queries.
    collection = paginated_collection.to_a

    # The offset collection and calculation is required so that we
    # know how much has been loaded in previous batches, collapsing
    # the current paginated set accordingly (collection limit calculation).
    # See: https://docs.gitlab.com/ee/development/diffs.html#diff-collection-limits
    #
    offset_index = collection.first&.index
    options = diff_options.dup

    collection =
      if offset_index && offset_index > 0
        offset_collection = relation.limit(offset_index)
        options[:offset_index] = offset_index
        offset_collection + collection
      else
        collection
      end

    Gitlab::Git::DiffCollection.new(collection.map(&:to_hash), options)
  end
end