Commit b904cebf authored by Cameron Swords's avatar Cameron Swords

Add index to build options for fast searching

parent d2d0df9b
......@@ -128,7 +128,7 @@ module Ci
scope :with_stale_live_trace, -> { with_live_trace.finished_before(12.hours.ago) }
scope :finished_before, -> (date) { finished.where('finished_at < ?', date) }
scope :with_secure_report_legacy, -> (job_type) { where('options like :job_type', job_type: "%#{job_type}%") }
scope :with_secure_report_legacy, -> (job_type) { where('options like :job_type', job_type: "%:artifacts:%:reports:%:#{job_type}:%") }
scope :with_secure_reports, -> (job_types) do
joins(:metadata).where("ci_builds_metadata.config_options -> 'artifacts' -> 'reports' ?| array[:job_types]", job_types: job_types)
......
# frozen_string_literal: true
class AddIndexToBuildOptions < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_build_on_options'
disable_ddl_transaction!
def up
add_concurrent_index :ci_builds, :options,
name: INDEX_NAME,
using: :gist,
opclass: :gist_trgm_ops,
where: "options like '%:artifacts:%:reports:%:sast:%'" \
" or options like '%:artifacts:%:reports:%:dast:%'" \
" or options like '%:artifacts:%:reports:%:dependency_scanning:%'" \
" or options like '%:artifacts:%:reports:%:container_scanning:%'"
end
def down
remove_concurrent_index_by_name :ci_builds, INDEX_NAME
end
end
......@@ -644,6 +644,7 @@ ActiveRecord::Schema.define(version: 2019_10_04_134055) do
t.index ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref"
t.index ["commit_id", "type", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_ref"
t.index ["name"], name: "index_ci_builds_on_name_for_security_products_values", where: "((name)::text = ANY (ARRAY[('container_scanning'::character varying)::text, ('dast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('license_management'::character varying)::text, ('sast'::character varying)::text]))"
t.index ["options"], name: "index_build_on_options", opclass: :gist_trgm_ops, where: "((options ~~ '%:artifacts:%:reports:%:sast:%'::text) OR (options ~~ '%:artifacts:%:reports:%:dast:%'::text) OR (options ~~ '%:artifacts:%:reports:%:dependency_scanning:%'::text) OR (options ~~ '%:artifacts:%:reports:%:container_scanning:%'::text))", using: :gist
t.index ["project_id", "id"], name: "index_ci_builds_on_project_id_and_id"
t.index ["project_id", "status"], name: "index_ci_builds_project_id_and_status_for_live_jobs_partial2", where: "(((type)::text = 'Ci::Build'::text) AND ((status)::text = ANY (ARRAY[('running'::character varying)::text, ('pending'::character varying)::text, ('created'::character varying)::text])))"
t.index ["project_id"], name: "index_ci_builds_on_project_id_for_successfull_pages_deploy", where: "(((type)::text = 'GenericCommitStatus'::text) AND ((stage)::text = 'deploy'::text) AND ((name)::text = 'pages:deploy'::text) AND ((status)::text = 'success'::text))"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment