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

SSP controller: avoid expensive subqueries #1172

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/controllers/api/v1/schedule_stop_pairs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def set_schedule_stop_pairs
# Feed Version, or default: All active Feed Versions
feed_version_sha1 = params[:feed_version_sha1].presence || params[:imported_from_feed_version].presence
if feed_version_sha1
@ssps = @ssps.where(feed_version: FeedVersion.find_by!(sha1: feed_version_sha1))
@ssps = @ssps.where(feed_version: FeedVersion.find_by!(sha1: feed_version_sha1).id)
end

# Explicitly use active Feed Versions
Expand All @@ -92,7 +92,7 @@ def set_schedule_stop_pairs
# Feed
feed_onestop_id = params[:feed_onestop_id].presence || params[:imported_from_feed].presence
if feed_onestop_id
@ssps = @ssps.where(feed: Feed.find_by_onestop_id!(feed_onestop_id))
@ssps = @ssps.where(feed: Feed.find_by_onestop_id!(feed_onestop_id).id)
end

# FeedVersion Import level
Expand All @@ -116,11 +116,11 @@ def set_schedule_stop_pairs

# Service between stops
if params[:origin_onestop_id].present?
origin_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :origin_onestop_id))
origin_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :origin_onestop_id)).pluck(:id)
@ssps = @ssps.where(origin: origin_stops)
end
if params[:destination_onestop_id].present?
destination_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :destination_onestop_id))
destination_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :destination_onestop_id)).pluck(:id)
@ssps = @ssps.where(destination: destination_stops)
end

Expand All @@ -144,15 +144,15 @@ def set_schedule_stop_pairs

# Service on a route
if params[:route_onestop_id].present?
routes = Route.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_onestop_id))
routes = Route.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_onestop_id)).pluck(:id)
@ssps = @ssps.where(route: routes)
end
if params[:route_stop_pattern_onestop_id].present?
rsps = RouteStopPattern.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_stop_pattern_onestop_id))
rsps = RouteStopPattern.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_stop_pattern_onestop_id)).pluck(:id)
@ssps = @ssps.where(route_stop_pattern: rsps)
end
if params[:operator_onestop_id].present?
operators = Operator.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :operator_onestop_id))
operators = Operator.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :operator_onestop_id)).pluck(:id)
@ssps = @ssps.where(operator: operators)
end

Expand Down