From 560146d88c0c8a49d723d63ce79a382b90431133 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 1 Feb 2025 20:09:38 +0300 Subject: [PATCH 1/2] Remove ids collected in parallel to model instances in map api --- app/controllers/api/maps_controller.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/maps_controller.rb b/app/controllers/api/maps_controller.rb index 2aa25fdd74..c37ba2a3e4 100644 --- a/app/controllers/api/maps_controller.rb +++ b/app/controllers/api/maps_controller.rb @@ -57,26 +57,18 @@ def show nodes += Node.includes(:node_tags).find(nodes_to_fetch) unless nodes_to_fetch.empty? - visible_nodes = {} @nodes = [] nodes.each do |node| - if node.visible? - visible_nodes[node.id] = node - @nodes << node - end + @nodes << node if node.visible? end @ways = [] - way_ids = [] ways.each do |way| - if way.visible? - way_ids << way.id - @ways << way - end + @ways << way if way.visible? end - @relations = Relation.nodes(visible_nodes.keys).visible + - Relation.ways(way_ids).visible + @relations = Relation.nodes(@nodes).visible + + Relation.ways(@ways).visible # we do not normally return the "other" partners referenced by an relation, # e.g. if we return a way A that is referenced by relation X, and there's From b9f1e311229e89a6cc2718a87cc9cbe3db2ca9e5 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 1 Feb 2025 20:19:00 +0300 Subject: [PATCH 2/2] Use filter instead of loop in visible node/way collections --- app/controllers/api/maps_controller.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/maps_controller.rb b/app/controllers/api/maps_controller.rb index c37ba2a3e4..9ba95c2551 100644 --- a/app/controllers/api/maps_controller.rb +++ b/app/controllers/api/maps_controller.rb @@ -57,15 +57,9 @@ def show nodes += Node.includes(:node_tags).find(nodes_to_fetch) unless nodes_to_fetch.empty? - @nodes = [] - nodes.each do |node| - @nodes << node if node.visible? - end + @nodes = nodes.filter(&:visible?) - @ways = [] - ways.each do |way| - @ways << way if way.visible? - end + @ways = ways.filter(&:visible?) @relations = Relation.nodes(@nodes).visible + Relation.ways(@ways).visible