Skip to content

Fix N+1 SQL queries in PipelinesController#show

Stan Hu requested to merge sh-fix-nplus-one-pipelines-show into master

In !56987 (merged), we lost the N+1 query optimizations used for legacy stages that were fixed by !21000 (merged).

To fix this issue, we use a similar approach used by that older merge request and preload the statuses dynamically using a StagePresenter. This dynamic preloading is necessary to filter out GenericCommitStatus, which does not have a tags association.

Note that we the newly-introduced with_latest_and_retried_statuses scope in the Ci::Stage model was just making extraneous queries that weren't being used. This happend because _stage.html.haml previously called latest_statuses and retried_statuses scopes, which actually wiped out any included assocations for stages.

Relates to #329417 (closed)

Edited by Stan Hu

Merge request reports