Skip to content

Commit

Permalink
Filter out invisible nodes and ways during initial selection
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Feb 2, 2025
1 parent 5f7dd9d commit b4c0c62
Showing 1 changed file with 6 additions and 10 deletions.
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

0 comments on commit b4c0c62

Please sign in to comment.