Fix a performance issue in Helm#can_uninstall?
What does this MR do?
Calling #present? was causing a DB query to happen each time around the loop. We only wanted to check for nil as it's nil in the first loop around so there is no need for #present?
Digging in appears this .present?
is actually really really bad for performance because it executes the following query:
SELECT "clusters_applications_helm".* FROM "clusters_applications_helm" WHERE (EXISTS (SELECT 1 FROM "clusters_applications_ingress" WHERE "clusters_applications_ingress"."cluster_id" = 22))
Which then loads every single clusters_applications_helm
as a rails model triggering all of the after_initialize
hooks which then accounts for why we see 69K invocations of Clusters::Applications::Helm#set_initial_status
.
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry for user-facing changes, or community contribution. Check the link for other scenarios.
- [-] 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
Closes #65963 (closed)
Edited by 🤖 GitLab Bot 🤖