[openstreetmap/openstreetmap-website] add bulk_upload (#1995)

mmd notifications at github.com
Wed Oct 3 09:32:47 UTC 2018


mmd-osm commented on this pull request.



> @@ -164,6 +172,65 @@ def delete_with_history!(new_node, user)
     end
   end
 
+  def self.delete_with_history_bulk!(nodes, changeset, if_unused = false)
+    node_hash = nodes.collect { |node| [node.id, node] }.to_h
+    skipped = {}
+    Node.transaction do
+      # check if node ids exists
+      node_ids = node_hash.keys
+      old_nodes = Node.select("id, version, visible").where(:id => node_ids).lock
+      raise OSM::APIBadUserInput, "Node not exist. id: " + (node_ids - old_nodes.collect(&:id)).join(", ") unless node_ids.length == old_nodes.length

Non-existing object should return HTTP 404 (Not found) instead of HTTP 400 (Bad Request)

> @@ -207,6 +218,54 @@ def delete_with_history!(new_relation, user)
     end
   end
 
+  def self.delete_with_history_bulk!(relations, changeset, if_unused = false)
+    relation_hash = relations.collect { |r| [r.id, r] }.to_h
+    skipped = {}
+    # need to start the transaction here, so that the database can
+    # provide repeatable reads for the used-by checks. this means it
+    # shouldn't be possible to get race conditions.
+    Relation.transaction do
+      relation_ids = relation_hash.keys
+      old_relations = Relation.select("id, version, visible").where(:id => relation_ids).lock
+      raise OSM::APIBadUserInput, "Relation not exist. id: " + (relation_ids - old_relations.collect(&:id)).join(", ") unless relation_ids.length == old_relations.length

Non-existing object should return HTTP 404 (Not found) instead of HTTP 400 (Bad Request)

> @@ -248,6 +300,55 @@ def delete_with_history!(new_way, user)
     end
   end
 
+  def self.delete_with_history_bulk!(ways, changeset, if_unused = false)
+    way_hash = ways.collect { |way| [way.id, way] }.to_h
+    skipped = {}
+    # need to start the transaction here, so that the database can
+    # provide repeatable reads for the used-by checks. this means it
+    # shouldn't be possible to get race conditions.
+    Way.transaction do
+      way_ids = way_hash.keys
+      old_ways = Way.select("id, version, visible").where(:id => way_ids).lock
+      raise OSM::APIBadUserInput, "Way not exist. id: " + (way_ids - old_ways.collect(&:id)).join(", ") unless way_ids.length == old_ways.length

Non-existing object should return HTTP 404 (Not found) instead of HTTP 400 (Bad Request)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/1995#pullrequestreview-161078984
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20181003/0923cc8a/attachment.html>


More information about the rails-dev mailing list