WIP: Optimize protected_branches
What does this MR do?
Optimize the Project protected branches
Queries
1. Protected branches per creator_id with no period
queries generated
Gitlab::UsageData.distinct_count(::Project.with_protected_branches.where(time_period), :creator_id)
SELECT MIN("projects"."creator_id") FROM "projects" INNER JOIN "protected_branches" ON "protected_branches"."project_id" = "projects"."id"
SELECT MAX("projects"."creator_id") FROM "projects" INNER JOIN "protected_branches" ON "protected_branches"."project_id" = "projects"."id"
SELECT COUNT(DISTINCT "projects"."creator_id") FROM "projects" INNER JOIN "protected_branches" ON "protected_branches"."project_id" = "projects"."id" WHERE "projects"."creator_id" BETWEEN $1 AND $2 [["creator_id", 1], ["creator_id", 10000]]
2. Protected branches per creator_id with period
queries generated
time_period = { created_at: 28.days.ago..Time.current }
Gitlab::UsageData.distinct_count(::Project.with_protected_branches.where(time_period), :creator_id)
SELECT MIN("projects"."creator_id") FROM "projects" INNER JOIN "protected_branches" ON "protected_branches"."project_id" = "projects"."id" WHERE "projects"."created_at" BETWEEN $1 AND $2 [["created_at", "2020-02-12 16:05:23.742703"], ["created_at", "2020-03-11 16:05:23.742877"]]
SELECT MAX("projects"."creator_id") FROM "projects" INNER JOIN "protected_branches" ON "protected_branches"."project_id" = "projects"."id" WHERE "projects"."created_at" BETWEEN $1 AND $2 [["created_at", "2020-02-12 16:05:23.742703"], ["created_at", "2020-03-11 16:05:23.742877"]]
SELECT COUNT(DISTINCT "projects"."creator_id") FROM "projects" INNER JOIN "protected_branches" ON "protected_branches"."project_id" = "projects"."id" WHERE "projects"."created_at" BETWEEN $1 AND $2 AND "projects"."creator_id" BETWEEN $3 AND $4 [["created_at", "2020-02-12 16:05:23.742703"], ["created_at", "2020-03-11 16:05:23.742877"], ["creator_id", 1], ["creator_id", 10000]]
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
Closes #210052 (closed)
Edited by Alina Mihaila