Fix timeouts on pipeline schedules page
What does this MR do?
- Indexes
ci_pipelines
on(pipeline_schedule_id, id)
, and removes now-redundant index on just(pipeline_schedule_id)
. This better facilitates accessing thelast_pipeline
has_one association onpipeline_schedules
, which usesorder(id: :desc)
to determine the latest pipeline. - Removes a very expensive preload of
last_pipeline
when viewing pipeline schedules. Some schedules have tens of thousands of pipelines, so it is in fact more efficient to load the last pipeline as an N+1 than to load every pipeline for all schedules and select the last one in Ruby.
Migration output
== 20201223012231 ReindexCiPipelinesOnScheduleIdAndId: reverting ==============
-- transaction_open?()
-> 0.0000s
-- index_exists?(:ci_pipelines, :pipeline_schedule_id, {:name=>"index_ci_pipelines_on_pipeline_schedule_id", :algorithm=>:concurrently})
-> 0.0099s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- add_index(:ci_pipelines, :pipeline_schedule_id, {:name=>"index_ci_pipelines_on_pipeline_schedule_id", :algorithm=>:concurrently})
-> 0.0052s
-- execute("RESET ALL")
-> 0.0002s
-- transaction_open?()
-> 0.0000s
-- indexes(:ci_pipelines)
-> 0.0078s
-- remove_index(:ci_pipelines, {:algorithm=>:concurrently, :name=>"index_ci_pipelines_on_pipeline_schedule_id_and_id"})
-> 0.0029s
== 20201223012231 ReindexCiPipelinesOnScheduleIdAndId: reverted (0.0271s) =====
== 20201223012231 ReindexCiPipelinesOnScheduleIdAndId: migrating ==============
-- transaction_open?()
-> 0.0000s
-- index_exists?(:ci_pipelines, [:pipeline_schedule_id, :id], {:name=>"index_ci_pipelines_on_pipeline_schedule_id_and_id", :algorithm=>:concurrently})
-> 0.0129s
-- execute("SET statement_timeout TO 0")
-> 0.0008s
-- add_index(:ci_pipelines, [:pipeline_schedule_id, :id], {:name=>"index_ci_pipelines_on_pipeline_schedule_id_and_id", :algorithm=>:concurrently})
-> 0.0100s
-- execute("RESET ALL")
-> 0.0003s
-- transaction_open?()
-> 0.0000s
-- indexes(:ci_pipelines)
-> 0.0136s
-- remove_index(:ci_pipelines, {:algorithm=>:concurrently, :name=>"index_ci_pipelines_on_pipeline_schedule_id"})
-> 0.0027s
== 20201223012231 ReindexCiPipelinesOnScheduleIdAndId: migrated (0.0419s) =====
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Related to #254664 (closed)
Edited by Tiger Watson