diff --git a/app/fetchers/service_plan_list_fetcher.rb b/app/fetchers/service_plan_list_fetcher.rb index 5d162a0ca04..6731ae746c3 100644 --- a/app/fetchers/service_plan_list_fetcher.rb +++ b/app/fetchers/service_plan_list_fetcher.rb @@ -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 diff --git a/app/models/services/service_plan.rb b/app/models/services/service_plan.rb index 2ea3b349df5..daa918bb8a3 100644 --- a/app/models/services/service_plan.rb +++ b/app/models/services/service_plan.rb @@ -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 @@ -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 diff --git a/db/migrations/20231113105256_add_service_plan_id_index.rb b/db/migrations/20231113105256_add_service_plan_id_index.rb new file mode 100644 index 00000000000..7d6870c20a2 --- /dev/null +++ b/db/migrations/20231113105256_add_service_plan_id_index.rb @@ -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