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

Filter out invisible nodes and ways during initial selection #5589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 6 additions & 10 deletions app/controllers/api/maps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,31 @@ def show
return
end

nodes = Node.bbox(@bounds).where(:visible => true).includes(:node_tags).limit(Settings.max_number_of_nodes + 1)
@nodes = Node.bbox(@bounds).visible.includes(:node_tags).limit(Settings.max_number_of_nodes + 1)

node_ids = nodes.collect(&:id)
node_ids = @nodes.collect(&:id)
if node_ids.length > Settings.max_number_of_nodes
report_error("You requested too many nodes (limit is #{Settings.max_number_of_nodes}). Either request a smaller area, or use planet.osm")
return
end

# get ways
# find which ways are needed
ways = []
@ways = []
if node_ids.empty?
list_of_way_nodes = []
else
way_nodes = WayNode.where(:node_id => node_ids)
way_ids = way_nodes.collect { |way_node| way_node.id[0] }
ways = Way.preload(:way_nodes, :way_tags).find(way_ids)
@ways = Way.preload(:way_nodes, :way_tags).visible.find(way_ids)

list_of_way_nodes = ways.flat_map { |way| way.way_nodes.map(&:node_id) }
list_of_way_nodes = @ways.flat_map { |way| way.way_nodes.map(&:node_id) }
end

# - [0] in case some thing links to node 0 which doesn't exist. Shouldn't actually ever happen but it does. FIXME: file a ticket for this
nodes_to_fetch = (list_of_way_nodes.uniq - node_ids) - [0]

nodes += Node.includes(:node_tags).find(nodes_to_fetch) unless nodes_to_fetch.empty?

@nodes = nodes.filter(&:visible?)

@ways = ways.filter(&:visible?)
@nodes += Node.includes(:node_tags).visible.find(nodes_to_fetch) unless nodes_to_fetch.empty?

@relations = Relation.nodes(@nodes).visible +
Relation.ways(@ways).visible
Expand Down