diff options
author | Dylan Griffith <dyl.griffith@gmail.com> | 2019-08-13 08:18:59 +0300 |
---|---|---|
committer | Dylan Griffith <dyl.griffith@gmail.com> | 2019-08-13 08:18:59 +0300 |
commit | dcdc04ab46f4be77db52454dc634593595ae7612 (patch) | |
tree | 13931d2c770d00c4e52c7a7d9287762465c95652 /spec/models | |
parent | fa70d12f0372bffff12d4385d465fe4b1c8d7a8e (diff) |
Fix performance issue in Helm#can_uninstall?
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?
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/clusters/applications/helm_spec.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb index d4f8b552088..00b5c72a3d3 100644 --- a/spec/models/clusters/applications/helm_spec.rb +++ b/spec/models/clusters/applications/helm_spec.rb @@ -23,7 +23,7 @@ describe Clusters::Applications::Helm do Clusters::Cluster::APPLICATIONS.keys.each do |application_name| next if application_name == 'helm' - it do + it "is false when #{application_name} is installed" do cluster_application = create("clusters_applications_#{application_name}".to_sym) helm = cluster_application.cluster.application_helm @@ -31,6 +31,14 @@ describe Clusters::Applications::Helm do expect(helm.allowed_to_uninstall?).to be_falsy end end + + it 'executes a single query only' do + cluster_application = create(:clusters_applications_ingress) + helm = cluster_application.cluster.application_helm + + query_count = ActiveRecord::QueryRecorder.new { helm.allowed_to_uninstall? }.count + expect(query_count).to eq(1) + end end context "without other existing applications" do |