Skip to content

Fix N+1 for searching commits

Dmitry Gruzd requested to merge 327006-fix-search-commits-n-plus-1 into master

What does this MR do?

When searching commits, for every unique commit author we execute the following query (N+1)

SELECT "users".* FROM ((SELECT "users".* FROM "users" WHERE (LOWER("users"."email") IN (LOWER('nicolo.mezzopera@gmail.com'))) AND "users"."confirmed_at" IS NOT NULL) UNION (SELECT "users".* FROM "users" INNER JOIN "emails" ON "emails"."user_id" = "users"."id" WHERE "emails"."email" = 'nicolo.mezzopera@gmail.com' AND "users"."confirmed_at" IS NOT NULL AND "emails"."confirmed_at" IS NOT NULL)) users

This MR fixes that and preloads all authors in 1 query in the prepare_commits_for_rendering method, which is called by SearchServicePresenter

Relates to gitlab-org/search-team/team-tasks#36 (closed)

#327006 (closed)

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Related to #327006 (closed)

Edited by Dmitry Gruzd

Merge request reports