]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
Eager load nodes and node tags for the way when doing a getway call.
[rails.git] / app / models / relation.rb
index 8a211b84f0498888108754c4b2e1bc70032a906c..d2602f497270c455d3d3a4b44062670eaac689bd 100644 (file)
@@ -87,7 +87,7 @@ class Relation < ActiveRecord::Base
     return doc
   end
 
-  def to_xml_node(user_display_name_cache = nil)
+  def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
     el1 = XML::Node.new 'relation'
     el1['id'] = self.id.to_s
     el1['visible'] = self.visible.to_s
@@ -95,19 +95,25 @@ class Relation < ActiveRecord::Base
     el1['version'] = self.version.to_s
     el1['changeset'] = self.changeset_id.to_s
 
-    user_display_name_cache = {} if user_display_name_cache.nil?
-    
-    if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
+    if changeset_cache.key?(self.changeset_id)
+      # use the cache if available
+    else
+      changeset_cache[self.changeset_id] = self.changeset.user_id
+    end
+
+    user_id = changeset_cache[self.changeset_id]
+
+    if user_display_name_cache.key?(user_id)
       # use the cache if available
     elsif self.changeset.user.data_public?
-      user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
+      user_display_name_cache[user_id] = self.changeset.user.display_name
     else
-      user_display_name_cache[self.changeset.user_id] = nil
+      user_display_name_cache[user_id] = nil
     end
 
-    if not user_display_name_cache[self.changeset.user_id].nil?
-      el1['user'] = user_display_name_cache[self.changeset.user_id]
-      el1['uid'] = self.changeset.user_id.to_s
+    if not user_display_name_cache[user_id].nil?
+      el1['user'] = user_display_name_cache[user_id]
+      el1['uid'] = user_id.to_s
     end
 
     self.relation_members.each do |member|
@@ -227,7 +233,7 @@ class Relation < ActiveRecord::Base
 
   def delete_with_history!(new_relation, user)
     unless self.visible
-      raise OSM::APIAlreadyDeletedError.new
+      raise OSM::APIAlreadyDeletedError.new("relation", new_relation.id)
     end
 
     # need to start the transaction here, so that the database can 
@@ -362,7 +368,6 @@ class Relation < ActiveRecord::Base
       tags_changed |= (not tags.empty?)
       RelationTag.delete_all(:id => self.id)
       self.tags.each do |k,v|
-        logger.info "TAG added: #{k} -> #{v}"
         tag = RelationTag.new
         tag.k = k
         tag.v = v