Fix more N+1 on notification settings page
What does this MR do?
This MR fixes N+1 queries in the Profiles::NotificationsController#show
action. The previous MR addressed N+1 queries related to @group_notifications
. This one fixes N+1 queries for @project_notifications
.
Page: https://gitlab.com/-/profile/notifications
There are two fixes:
- Preload namespace (and owner) or group with routes for the
source
(project). - Preload
MAX("project_authorizations"."access_level")
calculation for an array of projects by storing them in RequestStore.- The query is called deep within the policy, so it's difficult to preload it.
Screenshots (strongly suggested)
Before:
After:
DB query:
SELECT MAX("project_authorizations"."access_level") AS maximum_access_level, "project_authorizations"."project_id" AS project_authorizations_project_id
FROM "project_authorizations"
WHERE "project_authorizations"."user_id" = 4156052
AND "project_authorizations"."project_id" IN (13083, 13764, 14022, 14288, 14289)
GROUP BY "project_authorizations"."project_id"
- Maximum 20 project_ids.
- Plan: https://explain.depesz.com/s/Ev3V
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
-
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
Related to #21043 (closed)
Edited by Adam Hegyi