Skip to content

Fix N+1 problem in `JobsController#index`

Kamil Trzciński requested to merge fix-jobs-controller-index-n-1 into master

What does this MR do?

During Memory 102 we looked for some endpoint that has N+1 problem to fix it live during the demo.

We found the JobsController#index to be pretty bad. This makes this endpoint nice again.

This MR also introduces a matcher that looks for N+1 queries, the same query executed with different parameters.

This MR also revisits test (we were missing render_views!) fixes the following:

The following queries are executed more than 3 time(s):
---
SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2: 19
SELECT  "ci_builds_metadata".* FROM "ci_builds_metadata" WHERE "ci_builds_metadata"."build_id" = $1 LIMIT $2: 9
SELECT  "ci_trigger_requests".* FROM "ci_trigger_requests" WHERE "ci_trigger_requests"."id" = $1 LIMIT $2: 9
SELECT  "ci_job_artifacts".* FROM "ci_job_artifacts" WHERE "ci_job_artifacts"."job_id" = $1 AND "ci_job_artifacts"."file_type" = $2 LIMIT $3: 9
SELECT  "appearances".* FROM "appearances" ORDER BY "appearances"."id" ASC LIMIT $1: 7

Does this MR meet the acceptance criteria?

Conformity

Edited by 🤖 GitLab Bot 🤖

Merge request reports