Harden operations_dashboard_default_dashboard usage data queries
operations_dashboard_default_dashboard: count(::User.active.with_dashboard('operations').where(time_period)),
usage_activity_by_stage_monthly": {
"monitor": {
"operations_dashboard_default_dashboard": -1,
time_period = { created_at: 28.days.ago..Time.current }
Gitlab::UsageData.count(::User.active.with_dashboard('operations').where(time_period))
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'
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'
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 99999
gitlabhq_production=> 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';
min
---------
xxx
(1 row)
Time: 21630.276 ms (00:21.630)
gitlabhq_production=> 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'
gitlabhq_production-> ;
max
---------
xxx
(1 row)
Time: 1001.161 ms (00:01.001)
gitlabhq_production=> 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 99999
gitlabhq_production-> ;
count
-------
x
(1 row)
Solution
Add start
and finish
ID pre-calculated
Edited by Alper Akgun