Skip to content

Commit ff0c1b4

Browse files
committed
Filter out invisible nodes and ways during initial selection
1 parent 3cfb8b7 commit ff0c1b4

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Diff for: app/controllers/api/maps_controller.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,31 @@ def show
2828
return
2929
end
3030

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

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

3939
# get ways
4040
# find which ways are needed
41-
ways = []
41+
@ways = []
4242
if node_ids.empty?
4343
list_of_way_nodes = []
4444
else
4545
way_nodes = WayNode.where(:node_id => node_ids)
4646
way_ids = way_nodes.collect { |way_node| way_node.id[0] }
47-
ways = Way.preload(:way_nodes, :way_tags).find(way_ids)
47+
@ways = Way.preload(:way_nodes, :way_tags).visible.find(way_ids)
4848

49-
list_of_way_nodes = ways.flat_map { |way| way.way_nodes.map(&:node_id) }
49+
list_of_way_nodes = @ways.flat_map { |way| way.way_nodes.map(&:node_id) }
5050
end
5151

5252
# - [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
5353
nodes_to_fetch = (list_of_way_nodes.uniq - node_ids) - [0]
5454

55-
nodes += Node.includes(:node_tags).find(nodes_to_fetch) unless nodes_to_fetch.empty?
56-
57-
@nodes = nodes.filter(&:visible?)
58-
59-
@ways = ways.filter(&:visible?)
55+
@nodes += Node.includes(:node_tags).visible.find(nodes_to_fetch) unless nodes_to_fetch.empty?
6056

6157
@relations = Relation.nodes(@nodes).visible +
6258
Relation.ways(@ways).visible

0 commit comments

Comments
 (0)