diff options
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/ci/build_presenter.rb | 8 | ||||
-rw-r--r-- | app/presenters/ci/build_runner_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/ci/legacy_stage_presenter.rb | 13 | ||||
-rw-r--r-- | app/presenters/ci/stage_presenter.rb | 15 | ||||
-rw-r--r-- | app/presenters/commit_status_presenter.rb | 3 | ||||
-rw-r--r-- | app/presenters/packages/helm/index_presenter.rb | 23 | ||||
-rw-r--r-- | app/presenters/packages/npm/package_presenter.rb | 23 | ||||
-rw-r--r-- | app/presenters/project_presenter.rb | 18 | ||||
-rw-r--r-- | app/presenters/projects/import_export/project_export_presenter.rb | 1 | ||||
-rw-r--r-- | app/presenters/snippet_blob_presenter.rb | 6 |
10 files changed, 50 insertions, 62 deletions
diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb index 384cb3285fc..06ed6791bb7 100644 --- a/app/presenters/ci/build_presenter.rb +++ b/app/presenters/ci/build_presenter.rb @@ -12,11 +12,11 @@ module Ci erased_by.name if erased_by_user? end - def status_title + def status_title(status = detailed_status) if auto_canceled? "Job is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" else - tooltip_for_badge + tooltip_for_badge(status) end end @@ -41,8 +41,8 @@ module Ci private - def tooltip_for_badge - detailed_status.badge_tooltip.capitalize + def tooltip_for_badge(status) + status.badge_tooltip.capitalize end def detailed_status diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb index 0baee614568..b0066e2d7f0 100644 --- a/app/presenters/ci/build_runner_presenter.rb +++ b/app/presenters/ci/build_runner_presenter.rb @@ -33,7 +33,7 @@ module Ci end def runner_variables - if Feature.enabled?(:variable_inside_variable, project) + if Feature.enabled?(:variable_inside_variable, project, default_enabled: :yaml) variables.sort_and_expand_all(project, keep_undefined: true).to_runner_variables else variables.to_runner_variables diff --git a/app/presenters/ci/legacy_stage_presenter.rb b/app/presenters/ci/legacy_stage_presenter.rb index 56e268cff9f..d5c21baba28 100644 --- a/app/presenters/ci/legacy_stage_presenter.rb +++ b/app/presenters/ci/legacy_stage_presenter.rb @@ -15,18 +15,9 @@ module Ci private def preload_statuses(statuses) - loaded_statuses = statuses.load - statuses.tap do |statuses| - # rubocop: disable CodeReuse/ActiveRecord - ActiveRecord::Associations::Preloader.new.preload(preloadable_statuses(loaded_statuses), %w[tags job_artifacts_archive metadata]) - # rubocop: enable CodeReuse/ActiveRecord - end - end + Preloaders::CommitStatusPreloader.new(statuses).execute(Ci::StagePresenter::PRELOADED_RELATIONS) - def preloadable_statuses(statuses) - statuses.reject do |status| - status.instance_of?(::GenericCommitStatus) || status.instance_of?(::Ci::Bridge) - end + statuses end end end diff --git a/app/presenters/ci/stage_presenter.rb b/app/presenters/ci/stage_presenter.rb index 9ec3f8d153a..21bda86cded 100644 --- a/app/presenters/ci/stage_presenter.rb +++ b/app/presenters/ci/stage_presenter.rb @@ -4,6 +4,8 @@ module Ci class StagePresenter < Gitlab::View::Presenter::Delegated presents :stage + PRELOADED_RELATIONS = [:pipeline, :metadata, :tags, :job_artifacts_archive, :downstream_pipeline].freeze + def latest_ordered_statuses preload_statuses(stage.statuses.latest_ordered) end @@ -15,18 +17,9 @@ module Ci private def preload_statuses(statuses) - loaded_statuses = statuses.load - statuses.tap do |statuses| - # rubocop: disable CodeReuse/ActiveRecord - ActiveRecord::Associations::Preloader.new.preload(preloadable_statuses(loaded_statuses), %w[pipeline tags job_artifacts_archive metadata]) - # rubocop: enable CodeReuse/ActiveRecord - end - end + Preloaders::CommitStatusPreloader.new(statuses).execute(PRELOADED_RELATIONS) - def preloadable_statuses(statuses) - statuses.reject do |status| - status.instance_of?(::GenericCommitStatus) || status.instance_of?(::Ci::Bridge) - end + statuses end end end diff --git a/app/presenters/commit_status_presenter.rb b/app/presenters/commit_status_presenter.rb index 5f5bbf13f92..3c39470b730 100644 --- a/app/presenters/commit_status_presenter.rb +++ b/app/presenters/commit_status_presenter.rb @@ -27,7 +27,8 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated user_blocked: 'The user who created this job is blocked', ci_quota_exceeded: 'No more CI minutes available', no_matching_runner: 'No matching runner available', - trace_size_exceeded: 'The job log size limit was reached' + trace_size_exceeded: 'The job log size limit was reached', + builds_disabled: 'The CI/CD is disabled for this project' }.freeze private_constant :CALLOUT_FAILURE_MESSAGES diff --git a/app/presenters/packages/helm/index_presenter.rb b/app/presenters/packages/helm/index_presenter.rb index a6cfc61c94d..e85a4f248cf 100644 --- a/app/presenters/packages/helm/index_presenter.rb +++ b/app/presenters/packages/helm/index_presenter.rb @@ -8,11 +8,12 @@ module Packages API_VERSION = 'v1' CHANNEL = 'channel' INDEX_YAML_SUFFIX = "/#{CHANNEL}/index.yaml" + EMPTY_HASH = {}.freeze - def initialize(project, project_id_param, package_files) - @project = project + def initialize(project_id_param, channel, packages) @project_id_param = project_id_param - @package_files = package_files + @channel = channel + @packages = packages end def api_version @@ -20,10 +21,12 @@ module Packages end def entries - files = @package_files.preload_helm_file_metadata + return EMPTY_HASH unless @channel.present? + result = Hash.new { |h, k| h[k] = [] } - files.find_each do |package_file| + # this .each is safe as we have max 300 objects + most_recent_package_files.each do |package_file| name = package_file.helm_metadata['name'] result[name] << package_file.helm_metadata.merge({ 'created' => package_file.created_at.utc.strftime('%Y-%m-%dT%H:%M:%S.%NZ'), @@ -48,6 +51,16 @@ module Packages 'contextPath' => path.delete_suffix(INDEX_YAML_SUFFIX) } end + + private + + def most_recent_package_files + ::Packages::PackageFile.most_recent_for( + @packages, + extra_join: :helm_file_metadatum, + extra_where: { packages_helm_file_metadata: { channel: @channel } } + ).preload_helm_file_metadata + end end end end diff --git a/app/presenters/packages/npm/package_presenter.rb b/app/presenters/packages/npm/package_presenter.rb index 4e147b4739e..b9595eb6647 100644 --- a/app/presenters/packages/npm/package_presenter.rb +++ b/app/presenters/packages/npm/package_presenter.rb @@ -7,8 +7,6 @@ module Packages attr_reader :name, :packages - NPM_VALID_DEPENDENCY_TYPES = %i[dependencies devDependencies bundleDependencies peerDependencies].freeze - def initialize(name, packages) @name = name @packages = packages @@ -17,12 +15,16 @@ module Packages def versions package_versions = {} - packages.each do |package| - package_file = package.package_files.last + packages.each_batch do |relation| + relation.including_dependency_links + .preload_files + .each do |package| + package_file = package.package_files.last - next unless package_file + next unless package_file - package_versions[package.version] = build_package_version(package, package_file) + package_versions[package.version] = build_package_version(package, package_file) + end end package_versions @@ -59,11 +61,8 @@ module Packages def build_package_dependencies(package) dependencies = Hash.new { |h, key| h[key] = {} } - dependency_links = package.dependency_links - .with_dependency_type(NPM_VALID_DEPENDENCY_TYPES) - .includes_dependency - dependency_links.find_each do |dependency_link| + package.dependency_links.each do |dependency_link| dependency = dependency_link.dependency dependencies[dependency_link.dependency_type][dependency.name] = dependency.version_pattern end @@ -72,13 +71,13 @@ module Packages end def sorted_versions - versions = packages.map(&:version).compact + versions = packages.pluck_versions.compact VersionSorter.sort(versions) end def package_tags Packages::Tag.for_packages(packages) - .preload_package + .preload_package end end end diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb index 80a8ee5cb3c..066f4786cff 100644 --- a/app/presenters/project_presenter.rb +++ b/app/presenters/project_presenter.rb @@ -431,22 +431,10 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated private def integrations_anchor_data - experiment(:repo_integrations_link, project: project) do |e| - e.exclude! unless can?(current_user, :admin_project, project) - - e.use {} # nil control - e.try do - label = statistic_icon('settings') + _('Configure Integrations') - AnchorData.new(false, label, project_settings_integrations_path(project), nil, nil, nil, { - 'track-event': 'click', - 'track-experiment': e.name - }) - end - - e.run # call run so the return value will be the AnchorData (or nil) + return unless can?(current_user, :admin_project, project) - e.track(:view, value: project.id) # track an event for the view, with project id - end + label = statistic_icon('settings') + _('Configure Integrations') + AnchorData.new(false, label, project_settings_integrations_path(project), nil, nil, nil) end def cicd_missing? diff --git a/app/presenters/projects/import_export/project_export_presenter.rb b/app/presenters/projects/import_export/project_export_presenter.rb index 611294ddfd8..f56760b55df 100644 --- a/app/presenters/projects/import_export/project_export_presenter.rb +++ b/app/presenters/projects/import_export/project_export_presenter.rb @@ -34,7 +34,6 @@ module Projects # We need `.connected_to_user` here otherwise when a group has an # invitee, it would make the following query return 0 rows since a NULL # user_id would be present in the subquery - # See http://stackoverflow.com/questions/129077/not-in-clause-and-null-values non_null_user_ids = project.project_members.connected_to_user.select(:user_id) GroupMembersFinder.new(project.group).execute.where.not(user_id: non_null_user_ids) end diff --git a/app/presenters/snippet_blob_presenter.rb b/app/presenters/snippet_blob_presenter.rb index 0003a13a7bc..ab8fc0f905b 100644 --- a/app/presenters/snippet_blob_presenter.rb +++ b/app/presenters/snippet_blob_presenter.rb @@ -17,6 +17,10 @@ class SnippetBlobPresenter < BlobPresenter snippet_blob_raw_route end + def raw_directory + raw_path.rpartition("/").first + "/" + end + def raw_plain_data blob.data unless blob.binary? end @@ -33,7 +37,7 @@ class SnippetBlobPresenter < BlobPresenter def render_rich_partial renderer.render("projects/blob/viewers/_#{blob.rich_viewer.partial_name}", - locals: { viewer: blob.rich_viewer, blob: blob, blob_raw_path: raw_path, blob_raw_url: raw_url }, + locals: { viewer: blob.rich_viewer, blob: blob, blob_raw_path: raw_path, blob_raw_url: raw_url, parent_dir_raw_path: raw_directory }, layout: false) end |