Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch service plan visibilities with eager loading #3507

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/fetchers/service_plan_list_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class << self
def fetch(message, omniscient: false, readable_orgs_query: nil, readable_spaces_query: nil, eager_loaded_associations: [])
super(ServicePlan,
message,
omniscient:,
readable_orgs_query:,
readable_spaces_query:,
eager_loaded_associations:)
omniscient: omniscient,
readable_orgs_query: readable_orgs_query,
readable_spaces_query: readable_spaces_query,
eager_loaded_associations: eager_loaded_associations.append(:orgs_visibility))
end

private
Expand Down
4 changes: 3 additions & 1 deletion app/models/services/service_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ServicePlan < Sequel::Model

add_association_dependencies service_plan_visibilities: :destroy

one_to_many(:orgs_visibility, clone: :service_plan_visibilities) { |ds| ds.select(:service_plan_id).distinct }

one_to_many :labels, class: 'VCAP::CloudController::ServicePlanLabelModel', key: :resource_guid, primary_key: :guid
add_association_dependencies labels: :destroy

Expand Down Expand Up @@ -180,7 +182,7 @@ def visibility_type

return ServicePlanVisibilityTypes::SPACE if broker_space_scoped?

return ServicePlanVisibilityTypes::ORGANIZATION unless service_plan_visibilities_dataset.empty?
return ServicePlanVisibilityTypes::ORGANIZATION unless orgs_visibility.empty?

ServicePlanVisibilityTypes::ADMIN
end
Expand Down
9 changes: 9 additions & 0 deletions db/migrations/20231113105256_add_service_plan_id_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Sequel.migration do
up do
add_index :service_plan_visibilities, :service_plan_id, name: :spv_service_plan_id_index, options: [:concurrently] if database_type == :postgres
end

down do
drop_index :service_plan_visibilities, nil, name: :spv_service_plan_id_index, options: [:concurrently] if database_type == :postgres
end
end