]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/way.rb
Use tile based query when creating a way from unwayed segments.
[rails.git] / app / models / way.rb
index 09d1dafa0adca5b320aaad2003b63c36b9d85e43..c65119235372875d120c28f816e27dd3beb76ac6 100644 (file)
@@ -142,48 +142,47 @@ class Way < ActiveRecord::Base
     @tags[k] = v
   end
 
-  def save_with_history
-    begin
-      Way.transaction do
-        t = Time.now
-        self.timestamp = t
-        self.save!
+  def save_with_history!
+    t = Time.now
 
-        tags = self.tags
+    Way.transaction do
+      self.timestamp = t
+      self.save!
+    end
 
-        WayTag.delete_all(['id = ?', self.id])
+    WayTag.transaction do
+      tags = self.tags
 
-        tags.each do |k,v|
-          tag = WayTag.new
-          tag.k = k
-          tag.v = v
-          tag.id = self.id
-          tag.save!
-        end
+      WayTag.delete_all(['id = ?', self.id])
 
-        segs = self.segs
+      tags.each do |k,v|
+        tag = WayTag.new
+        tag.k = k
+        tag.v = v
+        tag.id = self.id
+        tag.save!
+      end
+    end
 
-        WaySegment.delete_all(['id = ?', self.id])
+    WaySegment.transaction do
+      segs = self.segs
 
-        i = 1
-        segs.each do |n|
-          seg = WaySegment.new
-          seg.id = self.id
-          seg.segment_id = n
-          seg.sequence_id = i
-          seg.save!
-          i += 1
-        end
+      WaySegment.delete_all(['id = ?', self.id])
 
-        old_way = OldWay.from_way(self)
-        old_way.timestamp = t
-        old_way.save_with_dependencies!
+      i = 1
+      segs.each do |n|
+        seg = WaySegment.new
+        seg.id = self.id
+        seg.segment_id = n
+        seg.sequence_id = i
+        seg.save!
+        i += 1
       end
-
-      return true
-    rescue
-      return nil
     end
+
+    old_way = OldWay.from_way(self)
+    old_way.timestamp = t
+    old_way.save_with_dependencies!
   end
 
   def preconditions_ok?