Skip to content

Commit 6c978fd

Browse files
committed
Optimise and fix queries, fix test description
1 parent ac21cf9 commit 6c978fd

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

app/models/runtime/space.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,8 @@ def find_visible_service_instance_by_name(name)
269269
(shared | source).first
270270
end
271271

272-
def number_service_instances
273-
service_instances_dataset.count
274-
end
275-
276272
def number_service_keys
277-
ServiceKey.where(service_instance_id: service_instances_dataset.select(:id)).count
273+
ServiceKey.join(:service_instances, id: :service_instance_id).where(service_instances__space_id: id).count
278274
end
279275

280276
def self.user_visibility_filter(user)

app/presenters/v3/space_usage_summary_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def to_hash
88
started_instances: started_instances,
99
memory_in_mb: space.memory_used,
1010
routes: space.routes_dataset.count,
11-
service_instances: space.number_service_instances,
11+
service_instances: space.service_instances_dataset.count,
1212
reserved_ports: VCAP::CloudController::SpaceReservedRoutePorts.new(space).count,
1313
domains: space.organization.owned_private_domains_dataset.count,
1414
per_app_tasks: space.running_and_pending_tasks_count,

spec/unit/controllers/v3/spaces_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@
962962
context 'when the user has permissions to read from the space' do
963963
before { allow_user_read_access_for(user, orgs: [org], spaces: [space]) }
964964

965-
it 'throws ResourceNotFound error' do
965+
it 'succeeds' do
966966
get :show_usage_summary, params: { guid: space.guid }
967967

968968
expect(response).to have_http_status(:ok)

0 commit comments

Comments
 (0)