Skip to content

Harden operations_dashboard_default_dashboard usage query

What does this MR do?

Harden operations_dashboard_default_dashboard usage data query by using precomputed user min/max id range

Query MIN

SELECT MIN("users"."id") FROM "users" WHERE ("users"."state" IN ('active')) AND ("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) AND "users"."dashboard" = 8 AND "users"."created_at" BETWEEN '2020-05-08 11:17:49.312323' AND '2020-06-05 11:17:49.312513'
Before: https://explain.depesz.com/s/LBDPU 406 seconds
After: precomputed value

Query MAX

SELECT MAX("users"."id") FROM "users" WHERE ("users"."state" IN ('active')) AND ("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) AND "users"."dashboard" = 8 AND "users"."created_at" BETWEEN '2020-05-08 11:17:49.312323' AND '2020-06-05 11:17:49.312513'
Before: https://explain.depesz.com/s/9qYN
After: precomputed value

Query Count

SELECT COUNT("users"."id") FROM "users" WHERE ("users"."state" IN ('active')) AND ("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) AND "users"."dashboard" = 8 AND "users"."created_at" BETWEEN '2020-05-08 11:17:49.312323' AND '2020-06-05 11:17:49.312513' AND "users"."id" BETWEEN 0 AND 9999
Before: https://explain.depesz.com/s/31Cx 337 milliseconds for a batch of 10K which is fine

Timing less than 5 seconds on gitlab.com

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

Closes #220479 (closed)

Edited by Alper Akgun

Merge request reports