Skip to content

Refactor admin/groups/show view to make less db calls

Gosia Ksionek requested to merge fix-sql-problems-in-admin-view into master

What does this MR do?

As the result of RoR performance training I have identified place where we make 3 calls to the same table 🤦

  1. any? is making a call
  2. count is making a second call
  3. then we call this table for actual records.

This changes are making only one call to db and then operate on loaded records.

Screenshots

Relevant part of logs before.

[1m[36mProject Exists? (1.2ms)[0m  [1m[34mSELECT 1 AS one FROM "projects" INNER JOIN "project_group_links" ON "projects"."id" = "project_group_links"."project_id" WHERE "project_group_links"."group_id" = $1 LIMIT $2[0m  [["group_id", 22], ["LIMIT", 1]]
  ↳ app/views/admin/groups/show.html.haml:81
  [1m[35m (0.6ms)[0m  [1m[34mSELECT COUNT(*) FROM "projects" INNER JOIN "project_group_links" ON "projects"."id" = "project_group_links"."project_id" WHERE "project_group_links"."group_id" = $1[0m  [["group_id", 22]]
  ↳ app/views/admin/groups/show.html.haml:86
  [1m[36mProject Load (0.7ms)[0m  [1m[34mSELECT "projects".* FROM "projects" INNER JOIN "project_group_links" ON "projects"."id" = "project_group_links"."project_id" WHERE "project_group_links"."group_id" = $1[0m  [["group_id", 22]]
  ↳ app/views/admin/groups/show.html.haml:88:in `sort_by'

Relevant part of logs after.

[1m[36mProject Load (1.0ms)[0m  [1m[34mSELECT "projects".* FROM "projects" INNER JOIN "project_group_links" ON "projects"."id" = "project_group_links"."project_id" WHERE "project_group_links"."group_id" = $1[0m  [["group_id", 22]]
  ↳ app/views/admin/groups/show.html.haml:81:in `sort_by'

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
Edited by Gosia Ksionek

Merge request reports