diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-13 12:11:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-13 12:11:10 +0300 |
commit | 37974ac0b196b06ffcc6cbea44385eaac1cc57bd (patch) | |
tree | 98450a46516f93a71018ec6b8d718fc023744575 /lib | |
parent | fcbd3db20f5dfb13ae33ddfee98be8d92cade72f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bulk_imports/groups/pipelines/entity_finisher.rb | 35 | ||||
-rw-r--r-- | lib/bulk_imports/importers/group_importer.rb | 45 | ||||
-rw-r--r-- | lib/gitlab/analytics/cycle_analytics/records_fetcher.rb | 54 | ||||
-rw-r--r-- | lib/gitlab/experimentation.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/pagination/offset_header_builder.rb | 21 |
5 files changed, 86 insertions, 73 deletions
diff --git a/lib/bulk_imports/groups/pipelines/entity_finisher.rb b/lib/bulk_imports/groups/pipelines/entity_finisher.rb new file mode 100644 index 00000000000..1d237bc0f7f --- /dev/null +++ b/lib/bulk_imports/groups/pipelines/entity_finisher.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module BulkImports + module Groups + module Pipelines + class EntityFinisher + def initialize(context) + @context = context + end + + def run + return if context.entity.finished? + + context.entity.finish! + + logger.info( + bulk_import_id: context.bulk_import.id, + bulk_import_entity_id: context.entity.id, + bulk_import_entity_type: context.entity.source_type, + pipeline_class: self.class.name, + message: 'Entity finished' + ) + end + + private + + attr_reader :context + + def logger + @logger ||= Gitlab::Import::Logger.build + end + end + end + end +end diff --git a/lib/bulk_imports/importers/group_importer.rb b/lib/bulk_imports/importers/group_importer.rb deleted file mode 100644 index 2cd97c687e0..00000000000 --- a/lib/bulk_imports/importers/group_importer.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -module BulkImports - module Importers - class GroupImporter - def initialize(entity) - @entity = entity - end - - def execute - pipelines.each.with_index do |pipeline, stage| - pipeline_tracker = entity.trackers.create!( - pipeline_name: pipeline, - stage: stage - ) - - context = BulkImports::Pipeline::Context.new(pipeline_tracker) - - pipeline.new(context).run - - pipeline_tracker.finish! - end - - entity.finish! - end - - private - - attr_reader :entity - - def pipelines - [ - BulkImports::Groups::Pipelines::GroupPipeline, - BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline, - BulkImports::Groups::Pipelines::MembersPipeline, - BulkImports::Groups::Pipelines::LabelsPipeline, - BulkImports::Groups::Pipelines::MilestonesPipeline, - BulkImports::Groups::Pipelines::BadgesPipeline - ] - end - end - end -end - -BulkImports::Importers::GroupImporter.prepend_if_ee('EE::BulkImports::Importers::GroupImporter') diff --git a/lib/gitlab/analytics/cycle_analytics/records_fetcher.rb b/lib/gitlab/analytics/cycle_analytics/records_fetcher.rb index 178ebe0d4d4..b4752ed9e5b 100644 --- a/lib/gitlab/analytics/cycle_analytics/records_fetcher.rb +++ b/lib/gitlab/analytics/cycle_analytics/records_fetcher.rb @@ -31,14 +31,34 @@ module Gitlab @params = params @sort = params[:sort] || :end_event @direction = params[:direction] || :desc + @page = params[:page] || 1 + @per_page = MAX_RECORDS end + # rubocop: disable CodeReuse/ActiveRecord def serialized_records strong_memoize(:serialized_records) do # special case (legacy): 'Test' and 'Staging' stages should show Ci::Build records if default_test_stage? || default_staging_stage? + ci_build_join = mr_metrics_table + .join(build_table) + .on(mr_metrics_table[:pipeline_id].eq(build_table[:commit_id])) + .join_sources + + records = ordered_and_limited_query + .joins(ci_build_join) + .select(build_table[:id], *time_columns) + + yield records if block_given? + ci_build_records = preload_ci_build_associations(records) + AnalyticsBuildSerializer.new.represent(ci_build_records.map { |e| e['build'] }) else + records = ordered_and_limited_query.select(*columns, *time_columns) + + yield records if block_given? + records = preload_associations(records) + records.map do |record| project = record.project attributes = record.attributes.merge({ @@ -51,10 +71,11 @@ module Gitlab end end end + # rubocop: enable CodeReuse/ActiveRecord private - attr_reader :stage, :query, :params, :sort, :direction + attr_reader :stage, :query, :params, :sort, :direction, :page, :per_page def columns MAPPINGS.fetch(subject_class).fetch(:columns_for_select).map do |column_name| @@ -74,41 +95,32 @@ module Gitlab MAPPINGS.fetch(subject_class).fetch(:serializer_class).new end - # Loading Ci::Build records instead of MergeRequest records # rubocop: disable CodeReuse/ActiveRecord - def ci_build_records - ci_build_join = mr_metrics_table - .join(build_table) - .on(mr_metrics_table[:pipeline_id].eq(build_table[:commit_id])) - .join_sources - - q = ordered_and_limited_query - .joins(ci_build_join) - .select(build_table[:id], *time_columns) - - results = execute_query(q).to_a + def preload_ci_build_associations(records) + results = records.map(&:attributes) Gitlab::CycleAnalytics::Updater.update!(results, from: 'id', to: 'build', klass: ::Ci::Build.includes({ project: [:namespace], user: [], pipeline: [] })) end + # rubocop: enable CodeReuse/ActiveRecord def ordered_and_limited_query - order_by(query, sort, direction, columns).limit(MAX_RECORDS) + strong_memoize(:ordered_and_limited_query) do + order_by(query, sort, direction, columns).page(page).per(per_page).without_count + end end - def records - results = ordered_and_limited_query - .select(*columns, *time_columns) - + # rubocop: disable CodeReuse/ActiveRecord + def preload_associations(records) # using preloader instead of includes to avoid AR generating a large column list ActiveRecord::Associations::Preloader.new.preload( - results, + records, MAPPINGS.fetch(subject_class).fetch(:includes_for_query) ) - results + records end - # rubocop: enable CodeReuse/ActiveRecord + # rubocop: enable CodeReuse/ActiveRecord def time_columns [ stage.start_event.timestamp_projection.as('start_event_timestamp'), diff --git a/lib/gitlab/experimentation.rb b/lib/gitlab/experimentation.rb index 1bb29ba3eac..145bb6d7b8f 100644 --- a/lib/gitlab/experimentation.rb +++ b/lib/gitlab/experimentation.rb @@ -34,10 +34,6 @@ module Gitlab module Experimentation EXPERIMENTS = { - upgrade_link_in_user_menu_a: { - tracking_category: 'Growth::Expansion::Experiment::UpgradeLinkInUserMenuA', - use_backwards_compatible_subject_index: true - }, invite_members_version_b: { tracking_category: 'Growth::Expansion::Experiment::InviteMembersVersionB', use_backwards_compatible_subject_index: true diff --git a/lib/gitlab/pagination/offset_header_builder.rb b/lib/gitlab/pagination/offset_header_builder.rb index 32089e40932..555f0e5a607 100644 --- a/lib/gitlab/pagination/offset_header_builder.rb +++ b/lib/gitlab/pagination/offset_header_builder.rb @@ -5,9 +5,9 @@ module Gitlab class OffsetHeaderBuilder attr_reader :request_context, :per_page, :page, :next_page, :prev_page, :total, :total_pages - delegate :params, :header, :request, to: :request_context + delegate :request, to: :request_context - def initialize(request_context:, per_page:, page:, next_page:, prev_page: nil, total:, total_pages:) + def initialize(request_context:, per_page:, page:, next_page:, prev_page: nil, total: nil, total_pages: nil, params: nil) @request_context = request_context @per_page = per_page @page = page @@ -15,6 +15,7 @@ module Gitlab @prev_page = prev_page @total = total @total_pages = total_pages + @params = params end def execute(exclude_total_headers: false, data_without_counts: false) @@ -56,10 +57,24 @@ module Gitlab end def page_href(next_page_params = {}) - query_params = params.merge(**next_page_params, per_page: params[:per_page]).to_query + query_params = params.merge(**next_page_params, per_page: per_page).to_query build_page_url(query_params: query_params) end + + def params + @params || request_context.params + end + + def header(name, value) + if request_context.respond_to?(:header) + # For Grape API + request_context.header(name, value) + else + # For rails controllers + request_context.response.headers[name] = value + end + end end end end |