Skip to content

Commit eb575b5

Browse files
authored
Improve service plan visibility check (readable orgs) (#4217)
When checking for the visibility of plans in readable orgs (SELECT 1 AS "one") neither potential duplicates nor the order of entries are important.
1 parent c230855 commit eb575b5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

app/fetchers/service_plan_visibility_fetcher.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@ def initialize(permission_queryer)
55
end
66

77
def fetch_orgs(service_plan_guids:)
8-
orgs_query(service_plan_guids:).all
8+
base_query(service_plan_guids:).
9+
select_all(:organizations).
10+
distinct(:organizations__id).
11+
order_by(:id).
12+
all
913
end
1014

1115
def any_orgs?(service_plan_guids:)
12-
orgs_query(service_plan_guids:).any?
16+
base_query(service_plan_guids:).any?
1317
end
1418

1519
private
1620

17-
def orgs_query(service_plan_guids:)
21+
def base_query(service_plan_guids:)
1822
dataset = Organization.dataset.
1923
join(:service_plan_visibilities, organization_id: :organizations__id).
2024
join(:service_plans, id: :service_plan_visibilities__service_plan_id).
2125
where(service_plans__guid: service_plan_guids)
2226

2327
dataset = dataset.where(organizations__guid: @permission_queryer.readable_org_guids_query) unless @permission_queryer.can_read_globally?
2428

25-
dataset.
26-
select_all(:organizations).
27-
distinct(:organizations__id).
28-
order_by(:id)
29+
dataset
2930
end
3031
end
3132
end

0 commit comments

Comments
 (0)