-
Notifications
You must be signed in to change notification settings - Fork 364
Replace .include? / .map with more efficient SQL statements #3041
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,7 +509,7 @@ def stopped? | |
end | ||
|
||
def uris | ||
routes.map(&:uri) | ||
routes_dataset.select_map(:uri) | ||
end | ||
|
||
def buildpack | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,12 +56,12 @@ def space_quota | |
end | ||
|
||
def filtered_visible_spaces | ||
visible_spaces = if @all_spaces_visible | ||
space_quota.spaces | ||
else | ||
space_quota.spaces.select { |space| @visible_space_guids.include? space.guid } | ||
end | ||
visible_spaces.map { |space| { guid: space.guid } } | ||
visible_spaces_dataset = if @all_spaces_visible | ||
space_quota.spaces_dataset | ||
else | ||
space_quota.spaces_dataset.where(guid: @visible_space_guids) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ultimately |
||
end | ||
visible_spaces_dataset.select_map(:guid).map { |guid| { guid: guid } } | ||
end | ||
|
||
def build_links | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,8 +239,8 @@ def can_read_route?(space_id) | |
space = VCAP::CloudController::Space.where(id: space_id).first | ||
|
||
space.has_member?(@user) || space.has_supporter?(@user) || | ||
@user.managed_organizations.map(&:id).include?(space.organization_id) || | ||
@user.audited_organizations.map(&:id).include?(space.organization_id) | ||
@user.managed_organizations_dataset.where(id: space.organization_id).any? || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as my first comment - the |
||
@user.audited_organizations_dataset.where(id: space.organization_id).any? | ||
end | ||
|
||
def space_guids_with_readable_routes_query | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely an improvement, but you can go further and cut out organizations table by doing something like
OrganizationManager.where(user_id: context.user.id, organization_id: space_quota_definition.organization.id).any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
managed organizations_dataset
produces this query: