From: Tom Hughes Date: Sun, 3 Feb 2008 12:56:25 +0000 (+0000) Subject: Optimise the Potlatch whichways and getway calls a bit. X-Git-Tag: live~7925 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d04c6d6ccd8d42fe3fc983433b8befe6a999dbdc?hp=bf41ed31d87eb1623f1aa91c159c3d98872ba5ee Optimise the Potlatch whichways and getway calls a bit. --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 2ef309fee..212343607 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -109,18 +109,14 @@ class AmfController < ApplicationController RAILS_DEFAULT_LOGGER.info(" Message: whichways, bbox=#{xmin},#{ymin},#{xmax},#{ymax}") # find the way ids in an area - nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax,:conditions => "visible = 1", :include => :way_nodes) - waynodes_in_area = nodes_in_area.collect {|node| node.way_nodes }.flatten - ways = waynodes_in_area.collect {|way_node| way_node.id[0]}.uniq + nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax, :conditions => "current_nodes.visible = 1", :include => :ways) + way_ids = nodes_in_area.collect { |node| node.way_ids }.flatten.uniq # find the node ids in an area that aren't part of ways - node_ids_in_area = nodes_in_area.collect {|node| node.id}.uniq - node_ids_used_in_ways = waynodes_in_area.collect {|way_node| way_node.node_id}.uniq - node_ids_not_used_in_area = node_ids_in_area - node_ids_used_in_ways - nodes_not_used_in_area = Node.find(node_ids_not_used_in_area) - points = nodes_not_used_in_area.collect {|n| [n.id, n.lon_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] } + nodes_not_used_in_area = nodes_in_area.select { |node| node.ways.empty? } + points = nodes_not_used_in_area.collect { |n| [n.id, n.lon_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] } - [ways,points] + [way_ids,points] end # ----- whichways_deleted @@ -171,13 +167,12 @@ class AmfController < ApplicationController RAILS_DEFAULT_LOGGER.info(" Message: getway, id=#{wayid}") - way = Way.find_eager(wayid) + way = Way.find(wayid, :include => :nodes) long_array = [] lat_array = [] points = [] - way.way_nodes.each do |way_node| - node = way_node.node # get the node record + way.nodes.each do |node| projected_longitude = node.lon_potlatch(baselong,masterscale) # do projection for potlatch projected_latitude = node.lat_potlatch(basey,masterscale) id = node.id diff --git a/app/models/node.rb b/app/models/node.rb index 37143ff00..ecaa3f45a 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -10,6 +10,7 @@ class Node < GeoRecord validates_numericality_of :latitude, :longitude validate :validate_position + has_many :ways, :through => :way_nodes has_many :old_nodes, :foreign_key => :id has_many :way_nodes belongs_to :user diff --git a/app/models/way.rb b/app/models/way.rb index 1126be9f5..f95037ea1 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -3,6 +3,7 @@ class Way < ActiveRecord::Base belongs_to :user + has_many :nodes, :through => :way_nodes, :order => 'sequence_id' has_many :way_nodes, :foreign_key => 'id', :order => 'sequence_id' has_many :way_tags, :foreign_key => 'id'