Remove unnecessary db query as admin user for update_route_destinations #2986
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
lib/cloud_controller/permissions.rb: 'readable_app_guids'
andapp/controllers/v3/routes_controller.rb: 'validate_app_guids!'
to avoid unnecessary SELECT statements without condition (SELECT guid FROM spaces
,SELECT guid FROM apps
).In one of our dashboards we saw a lot of
SELECT guid FROM spaces
queries without any filter. We found out that this query was originally triggered by readable_app_guids which used to call readable_space_guids in permissions.rb for the case when the user is an admin. To remove the unnecessary db query for admins, we replaced the readable_space_guidspart in readable_app_guids with:
VCAP::CloudController::AppModel.user_visible(@user, can_read_globally?).select(:guid).map(&:guid)
which is already done similar in other functions. With this change we make use of the user_visibility_filter of the sequel_plugin vcap_user_visibility, which is possible because this filter is implemented in the app_model.The above change showed in the dashboards another db query without filter,
SELECT guid FROM apps
, triggered in routes_controller.rb where readable_app_guids is called in validate_app_guids! for the case when the user is admin. In validate_app_guids we splitted the original unprocessable! case up into two scenarios:With this change the unnecessary db query for admin users can be avoided.
I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
main
branchI have run all the unit tests using
bundle exec rake
I have run CF Acceptance Tests