diff --git a/chrome/content/zotero/xpcom/collectionTreeRow.js b/chrome/content/zotero/xpcom/collectionTreeRow.js index 05b32479d..829f25387 100644 --- a/chrome/content/zotero/xpcom/collectionTreeRow.js +++ b/chrome/content/zotero/xpcom/collectionTreeRow.js @@ -31,6 +31,7 @@ Zotero.CollectionTreeRow = function(type, ref, level, isOpen) this.ref = ref; this.level = level || 0 this.isOpen = isOpen || false; + this.onUnload = null; } @@ -300,6 +301,18 @@ Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(fu } else if (this.isDuplicates()) { var s = yield this.ref.getSearchObject(); + let tmpTable; + for (let id in s.conditions) { + let c = s.conditions[id]; + if (c.condition == 'tempTable') { + tmpTable = c.value; + break; + } + } + // Called by ItemTreeView::unregister() + this.onUnload = async function () { + await Zotero.DB.queryAsync(`DROP TABLE IF EXISTS ${tmpTable}`); + }; } else { var s = new Zotero.Search(); diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index aaa953600..faf4dc7b9 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -1298,9 +1298,6 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { break; case 'tempTable': - if (!condition.value.match(/^[a-zA-Z0-9]+$/)) { - throw ("Invalid temp table '" + condition.value + "'"); - } condSQL += "itemID IN (SELECT id FROM " + condition.value + ")"; skipOperators = true; break; diff --git a/chrome/content/zotero/xpcom/duplicates.js b/chrome/content/zotero/xpcom/duplicates.js index 778483698..16b419827 100644 --- a/chrome/content/zotero/xpcom/duplicates.js +++ b/chrome/content/zotero/xpcom/duplicates.js @@ -45,31 +45,34 @@ Zotero.Duplicates.prototype.__defineGetter__('libraryID', function () { return t * * @return {Zotero.Search} */ -Zotero.Duplicates.prototype.getSearchObject = Zotero.Promise.coroutine(function* () { - yield Zotero.DB.executeTransaction(function* () { - var sql = "DROP TABLE IF EXISTS tmpDuplicates"; - yield Zotero.DB.queryAsync(sql); - - var sql = "CREATE TEMPORARY TABLE tmpDuplicates " - + "(id INTEGER PRIMARY KEY)"; - yield Zotero.DB.queryAsync(sql); - - yield this._findDuplicates(); - var ids = this._sets.findAll(true); - - Zotero.debug("Inserting rows into temp table"); - sql = "INSERT INTO tmpDuplicates VALUES (?)"; - for (let i=0; i