]> git.openstreetmap.org Git - rails.git/commitdiff
Merge branch 'p' of https://github.com/jfirebaugh/openstreetmap-website into jfirebaugh-p
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 22 Nov 2017 10:47:18 +0000 (10:47 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 22 Nov 2017 10:47:18 +0000 (10:47 +0000)
Refs #139

1  2 
app/controllers/api_controller.rb
app/controllers/relation_controller.rb
app/controllers/search_controller.rb
app/models/relation.rb

Simple merge
index 80fd519978fec4a74b0e17f35a1b0dcdedf886f4,af3c0753eacafb02705ac9dae04515cc778831dd..25532a95c72c0dc965f0ddeb1757099a7755773f
@@@ -91,38 -97,31 +91,34 @@@ class RelationController < ApplicationC
        # create XML.
        doc = OSM::API.new.get_xml_doc
        visible_nodes = {}
-       visible_members = { "Node" => {}, "Way" => {}, "Relation" => {} }
        changeset_cache = {}
        user_display_name_cache = {}
 -      
 +
        nodes.each do |node|
 -        if node.visible? # should be unnecessary if data is consistent.
 -          doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
 -          visible_nodes[node.id] = node
 -        end
 +        next unless node.visible? # should be unnecessary if data is consistent.
 +
 +        doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
 +        visible_nodes[node.id] = node
-         visible_members["Node"][node.id] = true
        end
 +
        ways.each do |way|
 -        if way.visible? # should be unnecessary if data is consistent.
 -          doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
 -        end
 +        next unless way.visible? # should be unnecessary if data is consistent.
 +
 +        doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
-         visible_members["Way"][way.id] = true
        end
 +
        relations.each do |rel|
 -        if rel.visible? # should be unnecessary if data is consistent.
 -          doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
 -        end
 +        next unless rel.visible? # should be unnecessary if data is consistent.
 +
-         doc.root << rel.to_xml_node(nil, changeset_cache, user_display_name_cache)
-         visible_members["Relation"][rel.id] = true
++        doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
        end
 +
        # finally add self and output
-       doc.root << relation.to_xml_node(visible_members, changeset_cache, user_display_name_cache)
+       doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache)
 -      render :text => doc.to_s, :content_type => "text/xml"
 -      
 +      render :xml => doc.to_s
 +
      else
 -      render :nothing => true, :status => :gone
 +      head :gone
      end
    end
  
index 4b8b2f402509655cb8efd5ed046fa54bc50ba324,78becc24b485f7be4bc000fd9ce7fdd05145d9b0..0d40b6691ab4e69e6fac431004d61a9327522e64
@@@ -91,9 -90,9 +91,9 @@@ class SearchController < ApplicationCon
      end
  
      relations.each do |rel|
-       doc.root << rel.to_xml_node(nil, changeset_cache, user_display_name_cache)
+       doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
      end
  
 -    render :text => doc.to_s, :content_type => "text/xml"
 +    render :xml => doc.to_s
    end
  end
index 275cafec24d29090b9e859aabaf2e94de22cd7ca,abe014311e61b07d29a4b12865a9f2c70f1d09f5..157794cd69cee7424771a248b0331b569f6d32d8
@@@ -118,44 -101,59 +118,32 @@@ class Relation < ActiveRecord::Bas
  
    def to_xml
      doc = OSM::API.new.get_xml_doc
 -    doc.root << to_xml_node()
 -    return doc
 +    doc.root << to_xml_node
 +    doc
    end
  
-   def to_xml_node(visible_members = nil, changeset_cache = {}, user_display_name_cache = {})
+   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
 -    el1['timestamp'] = self.timestamp.xmlschema
 -    el1['version'] = self.version.to_s
 -    el1['changeset'] = self.changeset_id.to_s
 -
 -    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]
 +    el = XML::Node.new "relation"
 +    el["id"] = id.to_s
  
 -    if user_display_name_cache.key?(user_id)
 -      # use the cache if available
 -    elsif self.changeset.user.data_public?
 -      user_display_name_cache[user_id] = self.changeset.user.display_name
 -    else
 -      user_display_name_cache[user_id] = nil
 -    end
 +    add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
  
 -    if not user_display_name_cache[user_id].nil?
 -      el1['user'] = user_display_name_cache[user_id]
 -      el1['uid'] = user_id.to_s
 +    relation_members.each do |member|
-       p = 0
-       if visible_members
-         # if there is a list of visible members then use that to weed out deleted segments
-         p = 1 if visible_members[member.member_type][member.member_id]
-       else
-         # otherwise, manually go to the db to check things
-         p = 1 if member.member.visible?
-       end
-       next unless p
 +      member_el = XML::Node.new "member"
 +      member_el["type"] = member.member_type.downcase
 +      member_el["ref"] = member.member_id.to_s
 +      member_el["role"] = member.member_role
 +      el << member_el
      end
  
 -    self.relation_members.each do |member|
 -      e = XML::Node.new 'member'
 -      e['type'] = member.member_type.downcase
 -      e['ref'] = member.member_id.to_s
 -      e['role'] = member.member_role
 -      el1 << e
 -    end
 +    add_tags_to_xml_node(el, relation_tags)
  
 -    self.relation_tags.each do |tag|
 -      e = XML::Node.new 'tag'
 -      e['k'] = tag.k
 -      e['v'] = tag.v
 -      el1 << e
 -    end
 -    return el1
 -  end 
 +    el
 +  end
  
 -  # FIXME is this really needed?
 +  # FIXME: is this really needed?
    def members
 -    @members ||= self.relation_members.map do |member|
 +    @members ||= relation_members.map do |member|
        [member.member_type, member.member_id, member.member_role]
      end
    end