cubicweb/server/sources/native.py
changeset 11351 97882e99138d
parent 11279 e4f11ef1face
child 11359 2da2dd60331c
--- a/cubicweb/server/sources/native.py	Mon Jun 06 15:18:12 2016 +0200
+++ b/cubicweb/server/sources/native.py	Tue May 10 16:09:34 2016 +0200
@@ -944,8 +944,16 @@
         * remove record from the `entities` table
         """
         self.fti_unindex_entities(cnx, entities)
-        attrs = {'eid': '(%s)' % ','.join([str(_e.eid) for _e in entities])}
-        self.doexec(cnx, self.sqlgen.delete_many('entities', attrs), attrs)
+
+        # sqlserver is limited on the array size, the limit can occur starting
+        # from > 10000 item, so we process by batch of 10000
+        count = len(entities)
+        batch_size = 10000
+        for i in range(0, count, batch_size):
+            in_eid = ",".join(str(entities[index].eid)
+                              for index in range(i, min(i + batch_size, count)))
+            attrs = {'eid': '(%s)' % (in_eid,)}
+            self.doexec(cnx, self.sqlgen.delete_many('entities', attrs), attrs)
 
     # undo support #############################################################