From d335d4dc537baa6775616fd57a773ad90c4855b9 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 11 Jun 2024 13:57:19 -0600 Subject: [PATCH] Optimize Org.with_template_and_user_counts (2/2) - This is a small addition to commit 67086970. - Rather than using all of the virtual attributes (org.has_users, org.has_contributors, org.has_plans), we 'combine' them into org.has_associations. - Basically, has_associations == (org.has_users || org.has_contributors || org.has_plans) - The corresponding changes are also made in app/views/paginable/orgs/_index.html.erb --- app/models/org.rb | 6 +++--- app/views/paginable/orgs/_index.html.erb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/org.rb b/app/models/org.rb index 09ae3475d..ff4dd4a0a 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -201,9 +201,9 @@ def self.default_orgs .group('orgs.id') .select("orgs.*, count(distinct templates.family_id) as template_count, - EXISTS (SELECT 1 FROM users WHERE users.org_id = orgs.id) AS has_users, - EXISTS (SELECT 1 FROM contributors WHERE contributors.org_id = orgs.id) AS has_contributors, - EXISTS (SELECT 1 FROM plans WHERE plans.org_id = orgs.id) as has_plans") + EXISTS (SELECT 1 FROM users WHERE users.org_id = orgs.id) OR + EXISTS (SELECT 1 FROM contributors WHERE contributors.org_id = orgs.id) OR + EXISTS (SELECT 1 FROM plans WHERE plans.org_id = orgs.id) as has_associations") } # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/views/paginable/orgs/_index.html.erb b/app/views/paginable/orgs/_index.html.erb index 5428659c6..0f88995a7 100644 --- a/app/views/paginable/orgs/_index.html.erb +++ b/app/views/paginable/orgs/_index.html.erb @@ -31,7 +31,7 @@