Improve caching of `project` and `grafana_integrations`
Problem to solve
It seems that we do not re-use project
of the imported project,
that results us requesting project multiple times. Request of project
is very expensive as: we need to fetch data, and we need to instantiate object.
We also seem to query for grafana_integrations
when processing markdown notes,
likely due to lib/banzai/filter/inline_grafana_metrics_filter.rb:44
.
Ideally, we should consider re-using existing project reference for all created objects, instead of getting the object from database.
Some idea is presented in !21176 (closed).
D, [2019-12-09T17:09:39.494892 #64] DEBUG -- : Project Load (0.4ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT $2 [["id", 43], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.494963 #64] DEBUG -- : ↳ app/models/event.rb:343
D, [2019-12-09T17:09:39.498671 #64] DEBUG -- : GrafanaIntegration Load (0.3ms) SELECT "grafana_integrations".* FROM "grafana_integrations" WHERE "grafana_integrations"."project_id" = $1 LIMIT $2 [["project_id", 43], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.498743 #64] DEBUG -- : ↳ lib/banzai/filter/inline_grafana_metrics_filter.rb:44
D, [2019-12-09T17:09:39.501601 #64] DEBUG -- : Route Load (0.3ms) SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = $1 AND "routes"."source_type" = $2 LIMIT $3 [["source_id", 43], ["source_type", "Project"], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.501671 #64] DEBUG -- : ↳ app/models/concerns/routable.rb:77
D, [2019-12-09T17:09:39.502652 #64] DEBUG -- : Milestone Load (0.4ms) SELECT "milestones".* FROM "milestones" WHERE ("milestones"."project_id" = $1 OR 1=0) AND "milestones"."iid" = $2 LIMIT $3 [["project_id", 43], ["iid", 2], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.502723 #64] DEBUG -- : ↳ app/finders/concerns/finder_methods.rb:12
D, [2019-12-09T17:09:39.503857 #64] DEBUG -- : Group Load (0.5ms) SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" IN ('Group') AND "namespaces"."id" = $1 AND "namespaces"."type" = $2 LIMIT $3 [["id", 1], ["type", "Group"], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.503929 #64] DEBUG -- : ↳ lib/banzai/filter/milestone_reference_filter.rb:112
D, [2019-12-09T17:09:39.504766 #64] DEBUG -- : Milestone Load (0.4ms) SELECT "milestones".* FROM "milestones" WHERE ("milestones"."project_id" = $1 OR 1=0) AND "milestones"."id" = $2 LIMIT $3 [["project_id", 43], ["id", 352], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.504835 #64] DEBUG -- : ↳ app/finders/concerns/finder_methods.rb:12
D, [2019-12-09T17:09:39.505630 #64] DEBUG -- : Project Load (0.4ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT $2 [["id", 43], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.505700 #64] DEBUG -- : ↳ app/helpers/milestones_routing_helper.rb:16
D, [2019-12-09T17:09:39.506597 #64] DEBUG -- : Namespace Load (0.3ms) SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.506663 #64] DEBUG -- : ↳ config/application.rb:288
D, [2019-12-09T17:09:39.507392 #64] DEBUG -- : Route Load (0.3ms) SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = $1 AND "routes"."source_type" = $2 LIMIT $3 [["source_id", 1], ["source_type", "Namespace"], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.507454 #64] DEBUG -- : ↳ app/models/concerns/routable.rb:77
D, [2019-12-09T17:09:39.508389 #64] DEBUG -- : Namespace Load (0.3ms) SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
D, [2019-12-09T17:09:39.508456 #64] DEBUG -- : ↳ app/models/project.rb:2376