Refactor admin/groups/show view to make less db calls
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
-
any?
is making a call -
count
is making a second call - 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
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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