]> git.openstreetmap.org Git - rails.git/blobdiff - lib/tasks/populate_node_tags.rake
split_node_tags: Merge changes in main branch up to r7649.
[rails.git] / lib / tasks / populate_node_tags.rake
index 186b44e5723a8c6e3d13eba1842aa7a9053f8e90..86747cfe4bf319fead0770ccd8a9ed76a25340a4 100644 (file)
@@ -3,17 +3,18 @@ namespace 'db' do
   task :node_tags  do
     require File.dirname(__FILE__) + '/../../config/environment'
 
   task :node_tags  do
     require File.dirname(__FILE__) + '/../../config/environment'
 
-    #"created_by=YahooApplet 1.0;highway=traffic_signals"
     node_count = Node.count
     node_count = Node.count
-    for n in (0..node_count)
-      Node.find(:all, :limit => 1, :offset => n).each do |node|
+    limit = 1000 #the number of nodes to grab in one go
+    offset = 0   
+
+    while offset < node_count
+        Node.find(:all, :limit => limit, :offset => offset).each do |node|
         seq_id = 1
         node.tags.split(';').each do |tag|
           nt = NodeTag.new
           nt.id = node.id
         seq_id = 1
         node.tags.split(';').each do |tag|
           nt = NodeTag.new
           nt.id = node.id
-          nt.k = tag.split('=')[0]
-          nt.v = tag.split('=')[1]
+          nt.k = tag.split('=')[0] || ''
+          nt.v = tag.split('=')[1] || ''
           nt.sequence_id = seq_id 
           nt.save! || raise
           seq_id += 1
           nt.sequence_id = seq_id 
           nt.save! || raise
           seq_id += 1
@@ -25,8 +26,8 @@ namespace 'db' do
         old_node.tags.split(';').each do |tag|
           ont = OldNodeTag.new
           ont.id = node.id #the id of the node tag
         old_node.tags.split(';').each do |tag|
           ont = OldNodeTag.new
           ont.id = node.id #the id of the node tag
-          ont.k = tag.split('=')[0]
-          ont.v = tag.split('=')[1]
+          ont.k = tag.split('=')[0] || ''
+          ont.v = tag.split('=')[1] || ''
           ont.version = version
           ont.sequence_id = sequence_id
           ont.save! || raise
           ont.version = version
           ont.sequence_id = sequence_id
           ont.save! || raise
@@ -35,6 +36,7 @@ namespace 'db' do
         version += 1
         end
       end
         version += 1
         end
       end
+    offset += limit
     end
   end
 end
     end
   end
 end