From 6ba6028ed07f4bd863cbace95ab6f817feccb86a Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 15 May 2019 15:47:37 -0400 Subject: [PATCH] Fix "too many SQL variables" deleting collection with >1000 items --- .../content/zotero/xpcom/data/collection.js | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index c5770a723f..002e6e72d2 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -630,19 +630,25 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env }.bind(this)); } - var placeholders = collections.map(() => '?').join(); - - // Remove item associations for all descendent collections - yield Zotero.DB.queryAsync('DELETE FROM collectionItems WHERE collectionID IN ' - + '(' + placeholders + ')', collections); - - // Remove parent definitions first for FK check - yield Zotero.DB.queryAsync('UPDATE collections SET parentCollectionID=NULL ' - + 'WHERE parentCollectionID IN (' + placeholders + ')', collections); - - // And delete all descendent collections - yield Zotero.DB.queryAsync ('DELETE FROM collections WHERE collectionID IN ' - + '(' + placeholders + ')', collections); + yield Zotero.Utilities.Internal.forEachChunkAsync( + collections, + Zotero.DB.MAX_BOUND_PARAMETERS, + async function (chunk) { + var placeholders = chunk.map(() => '?').join(); + + // Remove item associations for all descendent collections + await Zotero.DB.queryAsync('DELETE FROM collectionItems WHERE collectionID IN ' + + '(' + placeholders + ')', chunk); + + // Remove parent definitions first for FK check + await Zotero.DB.queryAsync('UPDATE collections SET parentCollectionID=NULL ' + + 'WHERE parentCollectionID IN (' + placeholders + ')', chunk); + + // And delete all descendent collections + await Zotero.DB.queryAsync('DELETE FROM collections WHERE collectionID IN ' + + '(' + placeholders + ')', chunk); + } + ); env.deletedObjectIDs = collections;