Improve performance of Search API (Advanced): commits scope
Summary
In &3166 (closed) a performance issue was raised around the response time of the Advanced Search API. This issue deals specifically with the commits
scope, at the Global, Group, and Project levels. Below are results of a performance test that was run on the 10k reference architecture:
API - Global Search
✓ { endpoint:commits }..........: avg=12506.79ms min=247.51ms med=14648.24ms max=17763.46ms p(90)=16896.01ms p(95)=17151.34ms
API - Group Search
✓ { endpoint:commits }..........: avg=9581.47ms min=2674.84ms med=9012.74ms max=21527.69ms p(90)=15041.66ms p(95)=17867.59ms
API - Project Search
✓ { endpoint:commits }..........: avg=5396.01ms min=1238.89ms med=5646.13ms max=9275.65ms p(90)=6737.16ms p(95)=7373.78ms
Improvements
Global
Queries
Started GET "/api/v4/search?scope=commits&search=*"
(0.4ms) SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))::float as lag
↳ app/models/concerns/cacheable_attributes.rb:19:in `current_without_cache'
ApplicationSetting Load (2.6ms) SELECT "application_settings".* FROM "application_settings" ORDER BY "application_settings"."id" DESC LIMIT 1
↳ app/models/concerns/cacheable_attributes.rb:19:in `current_without_cache'
PersonalAccessToken Load (0.8ms) SELECT "personal_access_tokens".* FROM "personal_access_tokens" WHERE "personal_access_tokens"."token_digest" = '' LIMIT 1
↳ app/models/concerns/token_authenticatable_strategies/digest.rb:8:in `find_token_authenticatable'
User Load (2.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
↳ lib/gitlab/auth/auth_finders.rb:103:in `find_user_from_access_token'
(0.5ms) SELECT "features"."key" FROM "features"
↳ lib/feature.rb:15:in `feature_names'
License Load (0.4ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT 1
↳ ee/app/models/license.rb:268:in `load_license'
Repository Search (19.8ms) {index: "gitlab-development", type: "doc", body: {query: {bool: {must: {simple_query_string: {fields: ["commit.message^10", "commit.sha^5", "commit.author.name^2", "commit.author.email^2", "commit.committer.name", "commit.committer.email"], query: "*", default_operator: :and}}, filter: [{term: {"type"=>"commit"}}, {has_parent: {parent_type: "project", query: {bool: {should: [{exists: {field: "id"}}, {bool: {filter: [{term: {visibility_level: 20}}, {term: {"repository_access_level"=>20}}]}}, {bool: {filter: [{term: {visibility_level: 10}}, {term: {"repository_access_level"=>20}}]}}], must_not: {term: {"repository_access_level"=>0}}}}}}]}}, size: 20, from: 0, sort: [:_score]}}
Project Load (3.5ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = 8
↳ ee/lib/elastic/latest/git_class_proxy.rb:205:in `yield_each_search_result'
Route Load (0.7ms) SELECT "routes".* FROM "routes" WHERE "routes"."source_type" = 'Project' AND "routes"."source_id" = 8
↳ ee/lib/elastic/latest/git_class_proxy.rb:205:in `yield_each_search_result'
ProjectFeature Load (0.8ms) SELECT "project_features".* FROM "project_features" WHERE "project_features"."project_id" = 8 LIMIT 1
↳ app/policies/project_policy.rb:539:in `feature_available?'
Namespace Load (1.7ms) SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 28 LIMIT 1
↳ config/application.rb:309:in `block (4 levels) in <class:Application>'
Route Load (0.4ms) SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 28 AND "routes"."source_type" = 'Namespace' LIMIT 1
↳ app/models/concerns/routable.rb:77:in `full_path'
Ci::Pipeline Load (7.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'ecd87f7cf58ebeae8bb7590bda5585215ef6fa78' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.9ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'ecd87f7cf58ebeae8bb7590bda5585215ef6fa78' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '8de232320aa3334160a9140ca007160ffbceb4f1' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '8de232320aa3334160a9140ca007160ffbceb4f1' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (1.0ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '0bb949575253965ac84b9afacf22747ee03c9376' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '0bb949575253965ac84b9afacf22747ee03c9376' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '937fcf292d7d50e10b7d1fca02da5adc9a4e3d01' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '937fcf292d7d50e10b7d1fca02da5adc9a4e3d01' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '210dc678fa114594277dcefc7989f56110784a6e' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '210dc678fa114594277dcefc7989f56110784a6e' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.9ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '4092e6cbe6249c188781b8a2979f1760ae4ec181' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '4092e6cbe6249c188781b8a2979f1760ae4ec181' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'bedeaf91f9a0e7e01915100ccd180e8268838ba4' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'bedeaf91f9a0e7e01915100ccd180e8268838ba4' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '0be7ab457a8838b0a7faff49bd718c952d9b7e8d' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '0be7ab457a8838b0a7faff49bd718c952d9b7e8d' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (1.1ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '070a0ba8b8c5bb210816c2531b347fd74225d684' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.7ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '070a0ba8b8c5bb210816c2531b347fd74225d684' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '7332121d63ede2e1c198a427b0568eeeb475c1a8' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '7332121d63ede2e1c198a427b0568eeeb475c1a8' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '67d364e091e67391f348f9074290c5b6a08e4890' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '67d364e091e67391f348f9074290c5b6a08e4890' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '5f1db10955bc981eb4e6cc229746327a44ec47de' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '5f1db10955bc981eb4e6cc229746327a44ec47de' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.7ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '6f01f432fb844ceb31a24157a20f7ffca3db1f14' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '6f01f432fb844ceb31a24157a20f7ffca3db1f14' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '0af551cb89579ecbff8b78d3f5edcb211302877c' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '0af551cb89579ecbff8b78d3f5edcb211302877c' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '154f5e116e36c7adf1035fc46ff4ecda73a31b6d' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.6ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '154f5e116e36c7adf1035fc46ff4ecda73a31b6d' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'f313936e8b46eca9ff15aad1eb19f91925c3c9bc' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'f313936e8b46eca9ff15aad1eb19f91925c3c9bc' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '6faf48600694045f539be3540253c6c252e32038' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '6faf48600694045f539be3540253c6c252e32038' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '7a33f7281963cc1bd1324a5d0fa4f874d4a73da1' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.4ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '7a33f7281963cc1bd1324a5d0fa4f874d4a73da1' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.7ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '1acecc461cf546fed295075b050bd42c66b2f196' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = '1acecc461cf546fed295075b050bd42c66b2f196' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
Ci::Pipeline Load (0.8ms) SELECT "ci_pipelines".* FROM "ci_pipelines" LEFT OUTER JOIN "ci_pipelines" "ci_pipelines_2" ON "ci_pipelines"."sha" = "ci_pipelines_2"."sha" AND "ci_pipelines"."project_id" = "ci_pipelines_2"."project_id" AND "ci_pipelines"."id" < "ci_pipelines_2"."id" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'c2d222decc481362a4b49295d9170f23d3c0fe0b' AND "ci_pipelines_2"."id" IS NULL
↳ app/models/ci/pipeline.rb:343:in `each_with_object'
Ci::Pipeline Load (0.5ms) SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 8 AND ("ci_pipelines"."config_source" IN (1, 2, 4, 5) OR "ci_pipelines"."config_source" IS NULL) AND "ci_pipelines"."sha" = 'c2d222decc481362a4b49295d9170f23d3c0fe0b' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
↳ app/models/commit_with_pipeline.rb:17:in `block in last_pipeline'
51 queries performed, with N+1 queries for ci_pipelines
.
Optimizing this will also improve Group and Project levels, as they do not override eager-loading behaviour.
Edited by Terri Chu