Skip to content

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

Performance 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 #65963 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports