and over again when processing a map call.
end
visible_nodes = {}
+ changeset_cache = {}
user_display_name_cache = {}
@nodes.each do |node|
if node.visible?
- doc.root << node.to_xml_node(user_display_name_cache)
+ doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
visible_nodes[node.id] = node
end
end
way_ids = Array.new
ways.each do |way|
if way.visible?
- doc.root << way.to_xml_node(visible_nodes, user_display_name_cache)
+ doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
way_ids << way.id
end
end
# this "uniq" may be slightly inefficient; it may be better to first collect and output
# all node-related relations, then find the *not yet covered* way-related ones etc.
relations.uniq.each do |relation|
- doc.root << relation.to_xml_node(user_display_name_cache)
+ doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache)
end
response.headers["Content-Disposition"] = "attachment; filename=\"map.osm\""
# create XML.
doc = OSM::API.new.get_xml_doc
visible_nodes = {}
+ 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(user_display_name_cache)
+ doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
visible_nodes[node.id] = node
end
end
ways.each do |way|
if way.visible? # should be unnecessary if data is consistent.
- doc.root << way.to_xml_node(visible_nodes, user_display_name_cache)
+ doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
end
end
relations.each do |rel|
if rel.visible? # should be unnecessary if data is consistent.
- doc.root << rel.to_xml_node(user_display_name_cache)
+ doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
end
end
# finally add self and output
- doc.root << relation.to_xml_node(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"
else
# Print
visible_nodes = {}
+ changeset_cache = {}
user_display_name_cache = {}
doc = OSM::API.new.get_xml_doc
nodes.each do |node|
- doc.root << node.to_xml_node(user_display_name_cache)
+ doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
visible_nodes[node.id] = node
end
ways.each do |way|
- doc.root << way.to_xml_node(visible_nodes, user_display_name_cache)
+ doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
end
relations.each do |rel|
- doc.root << rel.to_xml_node(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"
end
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 'node'
el1['id'] = self.id.to_s
el1['lat'] = self.lat.to_s
el1['lon'] = self.lon.to_s
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.tags.each do |k,v|
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
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|
return doc
end
- def to_xml_node(visible_nodes = nil, user_display_name_cache = nil)
+ def to_xml_node(visible_nodes = nil, changeset_cache = {}, user_display_name_cache = {})
el1 = XML::Node.new 'way'
el1['id'] = self.id.to_s
el1['visible'] = self.visible.to_s
el1['version'] = self.version.to_s
el1['changeset'] = self.changeset_id.to_s
- user_display_name_cache = {} if user_display_name_cache.nil?
+ 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 and user_display_name_cache.key?(self.changeset.user_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
# make sure nodes are output in sequence_id order