Improve #has_metrics? and Environment#has_terminals?
What does this MR do?
If an Deployment
is not success?
, no point running relatively expensive methods
Partly helps with https://gitlab.com/gitlab-org/gitlab-ce/issues/63475
Similar with Environment#has_metrics?
and Environment#has_terminals?
Before (master)
[2] pry(main)> e.available?
=> false
[3] pry(main)> e.has_metrics?
Project Load (1.8ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT $2 [["id", 15], ["LIMIT", 1]]
↳ app/models/environment.rb:181
License Load (0.2ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
↳ ee/app/models/license.rb:245
Clusters::Cluster Load (11.9ms) SELECT "clusters".* FROM "clusters" INNER JOIN "cluster_projects" ON "clusters"."id" = "cluster_projects"."cluster_id" WHERE "cluster_projects"."project_id" = $1 AND "clusters"."enabled" = $2 AND (environment_scope IN ('*', 'review/review-apps') OR
'review/review-apps' LIKE
REPLACE(REPLACE(REPLACE(environment_scope,
'%', '\%'),
'_', '\_'),
'*', '%')
) ORDER BY CASE environment_scope
WHEN '*' THEN 0
WHEN 'review/review-apps' THEN 2
ELSE 1
END DESC LIMIT $3 [["project_id", 15], ["enabled", "t"], ["LIMIT", 1]]
↳ ee/app/models/concerns/ee/deployment_platform.rb:13
Clusters::Platforms::Kubernetes Load (4.7ms) SELECT "cluster_platforms_kubernetes".* FROM "cluster_platforms_kubernetes" WHERE "cluster_platforms_kubernetes"."cluster_id" = $1 LIMIT $2 [["cluster_id", 42], ["LIMIT", 1]]
↳ ee/app/models/concerns/ee/deployment_platform.rb:13
License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
↳ ee/app/models/license.rb:245
License Load (0.2ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
↳ ee/app/models/license.rb:245
Service Load (4.6ms) SELECT "services".* FROM "services" WHERE "services"."project_id" = $1 [["project_id", 15]]
↳ app/models/project.rb:1158
Clusters::Applications::Prometheus Load (4.6ms) SELECT "clusters_applications_prometheus".* FROM "clusters_applications_prometheus" WHERE "clusters_applications_prometheus"."cluster_id" = $1 LIMIT $2 [["cluster_id", 42], ["LIMIT", 1]]
↳ app/services/prometheus/adapter_service.rb:33
=> nil
After
[6] pry(main)> e.available?
=> false
[7] pry(main)> e.has_metrics?
=> false
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] Documentation created/updated or follow-up review issue created
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Performance 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
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
Edited by 🤖 GitLab Bot 🤖