commit f3b461ae1d7f6ce20e9efc03a446390a6f57801a
parent a2d874c8bc9d0f1b8cc49460985e547200c57b59
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 20 Jun 2017 05:35:36 -0400
Don't use DB transaction when loading Duplicates Items
This should help avoid some timeouts when clicking into that view.
Diffstat:
4 files changed, 44 insertions(+), 29 deletions(-)
diff --git 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
@@ -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
@@ -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<ids.length; i++) {
- yield Zotero.DB.queryAsync(sql, [ids[i]], { debug: false })
+Zotero.Duplicates.prototype.getSearchObject = async function () {
+ var table = 'tmpDuplicates_' + Zotero.Utilities.randomString();
+
+ await this._findDuplicates();
+ var ids = this._sets.findAll(true);
+
+ // Zotero.CollectionTreeRow::getSearchObject() extracts the table name and creates an
+ // unload listener that drops the table when the ItemTreeView is unregistered
+ var sql = `CREATE TEMPORARY TABLE ${table} (id INTEGER PRIMARY KEY)`;
+ await Zotero.DB.queryAsync(sql);
+
+ Zotero.debug("Inserting rows into temp table");
+ sql = `INSERT INTO ${table} VALUES `;
+ await Zotero.Utilities.Internal.forEachChunkAsync(
+ ids,
+ Zotero.DB.MAX_BOUND_PARAMETERS,
+ async function (chunk) {
+ let idStr = '(' + chunk.join('), (') + ')';
+ await Zotero.DB.queryAsync(sql + idStr, false, { debug: false });
}
- Zotero.debug("Done");
- }.bind(this));
+ );
+ Zotero.debug("Done");
var s = new Zotero.Search;
s.libraryID = this._libraryID;
- s.addCondition('tempTable', 'is', 'tmpDuplicates');
+ s.addCondition('tempTable', 'is', table);
return s;
-});
+};
/**
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -1022,12 +1022,14 @@ Zotero.ItemTreeView.prototype.notify = Zotero.Promise.coroutine(function* (actio
}
});
-/*
- * Unregisters view from Zotero.Notifier (called on window close)
- */
-Zotero.ItemTreeView.prototype.unregister = function()
-{
+
+Zotero.ItemTreeView.prototype.unregister = async function() {
Zotero.Notifier.unregisterObserver(this._unregisterID);
+
+ if (this.collectionTreeRow.onUnload) {
+ await this.collectionTreeRow.onUnload();
+ }
+
if (this.listener) {
if (!this._treebox.treeBody) {
Zotero.debug("No more tree body in Zotero.ItemTreeView::unregister()");
@@ -1038,7 +1040,7 @@ Zotero.ItemTreeView.prototype.unregister = function()
tree.removeEventListener('keypress', this.listener, false);
this.listener = null;
}
-}
+};
////////////////////////////////////////////////////////////////////////////////
///