From e9e15046084c8f696b2e6f8410334b1580067d39 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 20 Aug 2025 19:04:35 +0100 Subject: [PATCH] Preload tags and members for API index and show operations --- app/controllers/api/nodes_controller.rb | 4 ++-- app/controllers/api/old_nodes_controller.rb | 9 +++++++-- app/controllers/api/old_relations_controller.rb | 9 +++++++-- app/controllers/api/old_ways_controller.rb | 9 +++++++-- app/controllers/api/relations_controller.rb | 4 ++-- app/controllers/api/ways_controller.rb | 3 ++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/nodes_controller.rb b/app/controllers/api/nodes_controller.rb index b7165b2fe..893f935bc 100644 --- a/app/controllers/api/nodes_controller.rb +++ b/app/controllers/api/nodes_controller.rb @@ -19,7 +19,7 @@ module Api raise OSM::APIBadUserInput, "No nodes were given to search for" if ids.empty? - @nodes = Node.find(ids) + @nodes = Node.includes(:element_tags).find(ids) # Render the result respond_to do |format| @@ -30,7 +30,7 @@ module Api # Dump the details on a node given in params[:id] def show - @node = Node.find(params[:id]) + @node = Node.includes(:element_tags).find(params[:id]) response.last_modified = @node.timestamp diff --git a/app/controllers/api/old_nodes_controller.rb b/app/controllers/api/old_nodes_controller.rb index b63761af9..0350cb6d0 100644 --- a/app/controllers/api/old_nodes_controller.rb +++ b/app/controllers/api/old_nodes_controller.rb @@ -3,11 +3,16 @@ module Api private def lookup_old_element - @old_element = OldNode.find([params[:node_id], params[:version]]) + @old_element = OldNode + .includes(:old_tags) + .find([params[:node_id], params[:version]]) end def lookup_old_element_versions - @elements = OldNode.where(:node_id => params[:node_id]).order(:version) + @elements = OldNode + .includes(:old_tags) + .where(:node_id => params[:node_id]) + .order(:version) end end end diff --git a/app/controllers/api/old_relations_controller.rb b/app/controllers/api/old_relations_controller.rb index c065c657d..9cd1413df 100644 --- a/app/controllers/api/old_relations_controller.rb +++ b/app/controllers/api/old_relations_controller.rb @@ -3,11 +3,16 @@ module Api private def lookup_old_element - @old_element = OldRelation.find([params[:relation_id], params[:version]]) + @old_element = OldRelation + .includes(:old_members, :old_tags) + .find([params[:relation_id], params[:version]]) end def lookup_old_element_versions - @elements = OldRelation.where(:relation_id => params[:relation_id]).order(:version) + @elements = OldRelation + .includes(:old_members, :old_tags) + .where(:relation_id => params[:relation_id]) + .order(:version) end end end diff --git a/app/controllers/api/old_ways_controller.rb b/app/controllers/api/old_ways_controller.rb index 654100767..ce6475b18 100644 --- a/app/controllers/api/old_ways_controller.rb +++ b/app/controllers/api/old_ways_controller.rb @@ -3,11 +3,16 @@ module Api private def lookup_old_element - @old_element = OldWay.find([params[:way_id], params[:version]]) + @old_element = OldWay + .includes(:old_nodes, :old_tags) + .find([params[:way_id], params[:version]]) end def lookup_old_element_versions - @elements = OldWay.where(:way_id => params[:way_id]).order(:version) + @elements = OldWay + .includes(:old_nodes, :old_tags) + .where(:way_id => params[:way_id]) + .order(:version) end end end diff --git a/app/controllers/api/relations_controller.rb b/app/controllers/api/relations_controller.rb index 146ac84c0..f9e113479 100644 --- a/app/controllers/api/relations_controller.rb +++ b/app/controllers/api/relations_controller.rb @@ -16,7 +16,7 @@ module Api raise OSM::APIBadUserInput, "No relations were given to search for" if ids.empty? - @relations = Relation.find(ids) + @relations = Relation.includes(:relation_members, :element_tags).find(ids) # Render the result respond_to do |format| @@ -26,7 +26,7 @@ module Api end def show - relation = Relation.find(params[:id]) + relation = Relation.includes(:relation_members, :element_tags).find(params[:id]) response.last_modified = relation.timestamp unless params[:full] diff --git a/app/controllers/api/ways_controller.rb b/app/controllers/api/ways_controller.rb index 08ad32e47..5de3bd9b5 100644 --- a/app/controllers/api/ways_controller.rb +++ b/app/controllers/api/ways_controller.rb @@ -16,7 +16,7 @@ module Api raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty? - @ways = Way.find(ids) + @ways = Way.includes(:nodes, :element_tags).find(ids) # Render the result respond_to do |format| @@ -27,6 +27,7 @@ module Api def show @way = Way + @way = @way.includes(:nodes, :element_tags) @way = @way.includes(:nodes => :element_tags) if params[:full] @way = @way.find(params[:id]) -- 2.39.5