EE::Project#latest_pipeline_with_security_reports query doesn't perform well
We're able to see the timeout on sentry https://sentry.gitlap.com/gitlab/gitlabcom/issues/476047/
https://gitlab.com/gitlab-com/gitlab-docs is being affected on it.
Query
SELECT "ci_pipelines".*
FROM "ci_pipelines"
INNER JOIN "ci_builds" ON "ci_builds"."commit_id" = "ci_pipelines"."id"
AND "ci_builds"."type" IN ('Ci::Build')
AND (
"ci_builds"."retried" = 'f'
OR "ci_builds"."retried" IS NULL
)
AND (
(
artifacts_file IS NOT NULL
AND artifacts_file <> ''
)
OR EXISTS (
SELECT 1
FROM "ci_job_artifacts"
WHERE (ci_builds.id = ci_job_artifacts.job_id)
AND "ci_job_artifacts"."file_type" = 1
)
)
AND (
artifacts_expire_at IS NULL
OR artifacts_expire_at > '2018-08-13 16:24:27.384098'
)
WHERE "ci_pipelines"."project_id" = 1794617
AND "ci_pipelines"."ref" = 'master'
AND "ci_builds"."name" IN (
'sast'
,'dependency_scanning'
,'sast:container'
,'container_scanning'
,'dast'
)
ORDER BY "ci_pipelines"."id" DESC LIMIT 1;
Edited by Oswaldo Ferreira