diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-15 21:07:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-15 21:07:01 +0300 |
commit | 854a0164ea775b84f5ef2508926780144bbc981a (patch) | |
tree | 648f210654b6a4f723061ae44e4265b6b15964e7 /lib | |
parent | a29eae68f453c371271641899e00ea24339fb1c6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
5 files changed, 44 insertions, 19 deletions
diff --git a/lib/gitlab/github_import/importer/attachments/base_importer.rb b/lib/gitlab/github_import/importer/attachments/base_importer.rb index eaff99aed43..844008f8087 100644 --- a/lib/gitlab/github_import/importer/attachments/base_importer.rb +++ b/lib/gitlab/github_import/importer/attachments/base_importer.rb @@ -16,9 +16,11 @@ module Gitlab batch.each do |record| next if already_imported?(record) - Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched) + if has_attachments?(record) + Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched) - yield record + yield record + end # We mark the object as imported immediately so we don't end up # scheduling it multiple times. @@ -48,6 +50,12 @@ module Gitlab def object_representation(object) representation_class.from_db_record(object) end + + def has_attachments?(object) + return true if Feature.disabled?(:github_importer_attachments, project, type: :gitlab_com_derisk) + + object_representation(object).has_attachments? + end end end end diff --git a/lib/gitlab/github_import/importer/note_attachments_importer.rb b/lib/gitlab/github_import/importer/note_attachments_importer.rb index 26472b0d468..36a256bbef5 100644 --- a/lib/gitlab/github_import/importer/note_attachments_importer.rb +++ b/lib/gitlab/github_import/importer/note_attachments_importer.rb @@ -16,10 +16,9 @@ module Gitlab end def execute - attachments = MarkdownText.fetch_attachments(note_text.text) - return if attachments.blank? + return unless note_text.has_attachments? - new_text = attachments.reduce(note_text.text) do |text, attachment| + new_text = note_text.attachments.reduce(note_text.text) do |text, attachment| new_url = gitlab_attachment_link(attachment) text.gsub(attachment.url, new_url) end diff --git a/lib/gitlab/github_import/markdown_text.rb b/lib/gitlab/github_import/markdown_text.rb index 8e9d6d8dd50..5880aa04358 100644 --- a/lib/gitlab/github_import/markdown_text.rb +++ b/lib/gitlab/github_import/markdown_text.rb @@ -41,6 +41,8 @@ module Gitlab def fetch_attachments(text) attachments = [] + return attachments if text.nil? + doc = CommonMarker.render_doc(text) doc.walk do |node| diff --git a/lib/gitlab/github_import/representation/note_text.rb b/lib/gitlab/github_import/representation/note_text.rb index 43e18a923d6..79bef4ec363 100644 --- a/lib/gitlab/github_import/representation/note_text.rb +++ b/lib/gitlab/github_import/representation/note_text.rb @@ -55,6 +55,14 @@ module Gitlab }.merge(record_type_specific_attribute) end + def has_attachments? + attachments.present? + end + + def attachments + @attachments ||= MarkdownText.fetch_attachments(text) + end + private def record_type_specific_attribute diff --git a/lib/gitlab/pagination/keyset/simple_order_builder.rb b/lib/gitlab/pagination/keyset/simple_order_builder.rb index cbd523389d6..ebed7bd94e4 100644 --- a/lib/gitlab/pagination/keyset/simple_order_builder.rb +++ b/lib/gitlab/pagination/keyset/simple_order_builder.rb @@ -34,18 +34,18 @@ module Gitlab elsif ordered_by_primary_key? primary_key_order # Ordered by one non-primary table column. Ex. 'ORDER BY created_at'. - elsif ordered_by_other_column? - column_with_tie_breaker_order + elsif ordered_by_other_columns? + columns_with_tie_breaker_order(order_values) # Ordered by two table columns with the last column as a tie breaker. Ex. 'ORDER BY created, id ASC'. - elsif ordered_by_other_column_with_tie_breaker? - tie_breaker_attribute = order_values.second + elsif ordered_by_other_columns_with_tie_breaker? + tie_breaker_attribute = order_values.last tie_breaker_column_order = Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( attribute_name: model_class.primary_key, order_expression: tie_breaker_attribute ) - column_with_tie_breaker_order(tie_breaker_column_order) + columns_with_tie_breaker_order(order_values[0...-1], tie_breaker_column_order) end order ? [scope.reorder!(order), true] : [scope, false] # [scope, success] @@ -120,10 +120,12 @@ module Gitlab ]) end - def column_with_tie_breaker_order(tie_breaker_column_order = default_tie_breaker_column_order) + def columns_with_tie_breaker_order(order_values, tie_breaker_column_order = default_tie_breaker_column_order) + other_columns = order_values.map { |order_value| column(order_value) } + Gitlab::Pagination::Keyset::Order.build( [ - column(order_values.first), + *other_columns, tie_breaker_column_order ]) end @@ -175,21 +177,27 @@ module Gitlab attribute && primary_key?(attribute) end - def ordered_by_other_column? - return unless order_values.one? + def ordered_by_other_columns? + return unless order_values.size >= 1 && !has_tie_breaker? - supported_column?(order_values.first) + supported_columns?(order_values) end - def ordered_by_other_column_with_tie_breaker? - return unless order_values.size == 2 + def ordered_by_other_columns_with_tie_breaker? + return unless order_values.size >= 2 && supported_columns?(order_values[0...-1]) - return unless supported_column?(order_values.first) + has_tie_breaker? + end - tie_breaker_attribute = order_values.second.try(:expr) + def has_tie_breaker? + tie_breaker_attribute = order_values.last.try(:expr) tie_breaker_attribute && primary_key?(tie_breaker_attribute) end + def supported_columns?(order_values) + order_values.all? { |order_value| supported_column?(order_value) } + end + def default_tie_breaker_column_order Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( attribute_name: model_class.primary_key, |