diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /lib/gitlab/diff | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r-- | lib/gitlab/diff/file.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/base.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/commit.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/compare.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/merge_request_diff_base.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/merge_request_diff_batch.rb | 33 | ||||
-rw-r--r-- | lib/gitlab/diff/position_tracer/line_strategy.rb | 21 |
7 files changed, 31 insertions, 51 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 35581952f4a..0ba23b8ffc7 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -449,7 +449,7 @@ module Gitlab end def alternate_viewer_class - return unless viewer.class == DiffViewer::Renamed + return unless viewer.instance_of?(DiffViewer::Renamed) find_renderable_viewer_class(RICH_VIEWERS) || (DiffViewer::Text if text?) end diff --git a/lib/gitlab/diff/file_collection/base.rb b/lib/gitlab/diff/file_collection/base.rb index f3f0f227a8c..6d04c4874c7 100644 --- a/lib/gitlab/diff/file_collection/base.rb +++ b/lib/gitlab/diff/file_collection/base.rb @@ -85,14 +85,14 @@ module Gitlab # No-op end + def overflow? + raw_diff_files.overflow? + end + private def empty_pagination_data - { - current_page: nil, - next_page: nil, - total_pages: nil - } + { total_pages: nil } end def diff_stats_collection diff --git a/lib/gitlab/diff/file_collection/commit.rb b/lib/gitlab/diff/file_collection/commit.rb index 7b1d6171e82..0f8f408d326 100644 --- a/lib/gitlab/diff/file_collection/commit.rb +++ b/lib/gitlab/diff/file_collection/commit.rb @@ -10,6 +10,10 @@ module Gitlab diff_options: diff_options, diff_refs: commit.diff_refs) end + + def cache_key + ['commit', @diffable.id] + end end end end diff --git a/lib/gitlab/diff/file_collection/compare.rb b/lib/gitlab/diff/file_collection/compare.rb index 663bad95db7..badebabb192 100644 --- a/lib/gitlab/diff/file_collection/compare.rb +++ b/lib/gitlab/diff/file_collection/compare.rb @@ -14,6 +14,10 @@ module Gitlab def unfold_diff_lines(positions) # no-op end + + def cache_key + ['compare', @diffable.head.id, @diffable.base.id] + end end end end diff --git a/lib/gitlab/diff/file_collection/merge_request_diff_base.rb b/lib/gitlab/diff/file_collection/merge_request_diff_base.rb index d2ca86fdfe7..692186fc323 100644 --- a/lib/gitlab/diff/file_collection/merge_request_diff_base.rb +++ b/lib/gitlab/diff/file_collection/merge_request_diff_base.rb @@ -6,6 +6,8 @@ module Gitlab class MergeRequestDiffBase < Base extend ::Gitlab::Utils::Override + delegate :real_size, :overflow?, :cache_key, to: :@merge_request_diff + def initialize(merge_request_diff, diff_options:) @merge_request_diff = merge_request_diff @@ -44,10 +46,6 @@ module Gitlab diff_stats_cache.clear end - def real_size - @merge_request_diff.real_size - end - private def highlight_cache @@ -58,7 +56,7 @@ module Gitlab def diff_stats_cache strong_memoize(:diff_stats_cache) do - Gitlab::Diff::StatsCache.new(cachable_key: @merge_request_diff.cache_key) + Gitlab::Diff::StatsCache.new(cachable_key: cache_key) end end 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 5ff7c88970c..0a601bde612 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,7 @@ module Gitlab @paginated_collection = load_paginated_collection(batch_page, batch_size, diff_options) @pagination_data = { - current_page: current_page, - next_page: next_page, - total_pages: total_pages + total_pages: @paginated_collection.blank? ? nil : relation.size } end @@ -62,24 +60,6 @@ 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 @@ -87,21 +67,12 @@ module Gitlab paths = diff_options&.fetch(:paths, nil) - paginated_collection = if batch_gradual_load? - relation.offset(batch_page).limit([batch_size.to_i, DEFAULT_BATCH_SIZE].min) - else - relation.page(batch_page).per(batch_size) - end - + paginated_collection = relation.offset(batch_page).limit([batch_size.to_i, DEFAULT_BATCH_SIZE].min) paginated_collection = paginated_collection.by_paths(paths) if paths paginated_collection end # rubocop: enable CodeReuse/ActiveRecord - - def batch_gradual_load? - Feature.enabled?(:diffs_gradual_load, @merge_request_diff.project, default_enabled: true) - end end end end diff --git a/lib/gitlab/diff/position_tracer/line_strategy.rb b/lib/gitlab/diff/position_tracer/line_strategy.rb index e3c1e549b96..8bacc781f61 100644 --- a/lib/gitlab/diff/position_tracer/line_strategy.rb +++ b/lib/gitlab/diff/position_tracer/line_strategy.rb @@ -95,7 +95,7 @@ module Gitlab if c_line # If the line is still in D but also in C, it has turned from an # added line into an unchanged one. - new_position = new_position(cd_diff, c_line, d_line) + new_position = new_position(cd_diff, c_line, d_line, position.line_range) if valid_position?(new_position) # If the line is still in the MR, we don't treat this as outdated. { position: new_position, outdated: false } @@ -108,7 +108,7 @@ module Gitlab end else # If the line is still in D and not in C, it is still added. - { position: new_position(cd_diff, nil, d_line), outdated: false } + { position: new_position(cd_diff, nil, d_line, position.line_range), outdated: false } end else # If the line is no longer in D, it has been removed from the MR. @@ -143,7 +143,7 @@ module Gitlab { position: new_position(bd_diff, nil, d_line), outdated: true } else # If the line is still in C and not in D, it is still removed. - { position: new_position(cd_diff, c_line, nil), outdated: false } + { position: new_position(cd_diff, c_line, nil, position.line_range), outdated: false } end else # If the line is no longer in C, it has been removed outside of the MR. @@ -174,7 +174,7 @@ module Gitlab if c_line && d_line # If the line is still in C and D, it is still unchanged. - new_position = new_position(cd_diff, c_line, d_line) + new_position = new_position(cd_diff, c_line, d_line, position.line_range) if valid_position?(new_position) # If the line is still in the MR, we don't treat this as outdated. { position: new_position, outdated: false } @@ -188,7 +188,7 @@ module Gitlab # If the line is still in D but no longer in C, it has turned from # an unchanged line into an added one. # We don't treat this as outdated since the line is still in the MR. - { position: new_position(cd_diff, nil, d_line), outdated: false } + { position: new_position(cd_diff, nil, d_line, position.line_range), outdated: false } else # !d_line && (c_line || !c_line) # If the line is no longer in D, it has turned from an unchanged line # into a removed one. @@ -196,12 +196,15 @@ module Gitlab end end - def new_position(diff_file, old_line, new_line) - Position.new( + def new_position(diff_file, old_line, new_line, line_range = nil) + params = { diff_file: diff_file, old_line: old_line, - new_line: new_line - ) + new_line: new_line, + line_range: line_range + }.compact + + Position.new(**params) end def valid_position?(position) |