f9565e3039
After installing a new gem, batch-loader, a construct can be used to queue data to be fetched in bulk. The gem was also introduced in both gitlab-org/gitlab-ce!14680 and gitlab-org/gitlab-ce!14846, but those mrs are not merged yet. For the generation of diffs, both the old blob and the new blob need to be loaded. This for every file in the diff, too. Now we collect all these so we do 1 fetch. Three `.allow_n_plus_1_calls` have been removed, which I expect to be valid, but this needs to be confirmed by a full CI run. Possibly closes: - https://gitlab.com/gitlab-org/gitlab-ce/issues/37445 - https://gitlab.com/gitlab-org/gitlab-ce/issues/37599 - https://gitlab.com/gitlab-org/gitlab-ce/issues/37431
44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
Ruby
module Gitlab
|
|
module Diff
|
|
module FileCollection
|
|
class Base
|
|
attr_reader :project, :diff_options, :diff_refs, :fallback_diff_refs
|
|
|
|
delegate :count, :size, :real_size, to: :diff_files
|
|
|
|
def self.default_options
|
|
::Commit.max_diff_options.merge(ignore_whitespace_change: false, expanded: false)
|
|
end
|
|
|
|
def initialize(diffable, project:, diff_options: nil, diff_refs: nil, fallback_diff_refs: nil)
|
|
diff_options = self.class.default_options.merge(diff_options || {})
|
|
|
|
@diffable = diffable
|
|
@diffs = diffable.raw_diffs(diff_options)
|
|
@project = project
|
|
@diff_options = diff_options
|
|
@diff_refs = diff_refs
|
|
@fallback_diff_refs = fallback_diff_refs
|
|
end
|
|
|
|
def diff_files
|
|
@diff_files ||= @diffs.decorate! { |diff| decorate_diff!(diff) }
|
|
end
|
|
|
|
def diff_file_with_old_path(old_path)
|
|
diff_files.find { |diff_file| diff_file.old_path == old_path }
|
|
end
|
|
|
|
def diff_file_with_new_path(new_path)
|
|
diff_files.find { |diff_file| diff_file.new_path == new_path }
|
|
end
|
|
|
|
private
|
|
|
|
def decorate_diff!(diff)
|
|
Gitlab::Diff::File.new(diff, repository: project.repository, diff_refs: diff_refs, fallback_diff_refs: fallback_diff_refs)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|