N+1 SQL regression in PipelinesController#show
If you go to https://gitlab.com/gitlab-org/gitlab-build-images/-/pipelines/294013653, you will see the performance bar show:
In !56987 (merged), dropping latest_ordered_statuses
and retried_ordered_statuses
in favor of latest_statuses
and retried_statuses
introduces these N+1 queries:
/*application:web,correlation_id:01F4E2KJV1CE6XKTBVQCYJWZCC,endpoint_id:Projects::PipelinesController#show*/ SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 1220800455 AND "taggings"."taggable_type" = 'CommitStatus' AND "taggings"."context" = 'tags'
From:
[
"ee/lib/ee/peek/views/active_record.rb:11:in `generate_detail'",
"lib/peek/views/active_record.rb:52:in `block in setup_subscribers'",
"app/views/projects/ci/builds/_build.html.haml:45",
"app/views/projects/stage/_stage.html.haml:9",
"app/views/projects/pipelines/_with_tabs.html.haml:42",
"app/views/projects/pipelines/show.html.haml:28",
"app/controllers/application_controller.rb:123:in `render'",
"app/controllers/projects/pipelines_controller.rb:229:in `block (2 levels) in render_show'",
"app/controllers/projects/pipelines_controller.rb:227:in `render_show'",
"app/controllers/projects/pipelines_controller.rb:108:in `block (2 levels) in show'",
"app/controllers/projects/pipelines_controller.rb:107:in `show'",
"app/controllers/application_controller.rb:536:in `block in allow_gitaly_ref_name_caching'",
"lib/gitlab/gitaly_client.rb:341:in `allow_ref_name_caching'",
"app/controllers/application_controller.rb:535:in `allow_gitaly_ref_name_caching'",
"ee/lib/gitlab/ip_address_state.rb:10:in `with'",
"ee/app/controllers/ee/application_controller.rb:44:in `set_current_ip_address'",
"app/controllers/application_controller.rb:485:in `set_current_admin'",
"lib/gitlab/session.rb:11:in `with_session'",
"app/controllers/application_controller.rb:476:in `set_session_storage'",
"app/controllers/application_controller.rb:470:in `set_locale'",
"app/controllers/application_controller.rb:463:in `block in set_current_context'",
"lib/gitlab/application_context.rb:70:in `block in use'",
"lib/gitlab/application_context.rb:70:in `use'",
"lib/gitlab/application_context.rb:27:in `with_context'",
"app/controllers/application_controller.rb:454:in `set_current_context'",
"ee/lib/omni_auth/strategies/group_saml.rb:41:in `other_phase'",
"lib/gitlab/jira/middleware.rb:19:in `call'"
]
That's because we are no longer calling this preload: https://gitlab.com/gitlab-org/gitlab/blob/d7e2a7f68b1ba8b6565c210997627821cf4ea897/app/presenters/ci/legacy_stage_presenter.rb#L21
Edited by Stan Hu