Don't use DB transaction when loading Duplicates Items
This should help avoid some timeouts when clicking into that view.
This commit is contained in:
parent
a2d874c8bc
commit
f3b461ae1d
4 changed files with 44 additions and 29 deletions
|
@ -31,6 +31,7 @@ Zotero.CollectionTreeRow = function(type, ref, level, isOpen)
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
this.level = level || 0
|
this.level = level || 0
|
||||||
this.isOpen = isOpen || false;
|
this.isOpen = isOpen || false;
|
||||||
|
this.onUnload = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,6 +301,18 @@ Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(fu
|
||||||
}
|
}
|
||||||
else if (this.isDuplicates()) {
|
else if (this.isDuplicates()) {
|
||||||
var s = yield this.ref.getSearchObject();
|
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 {
|
else {
|
||||||
var s = new Zotero.Search();
|
var s = new Zotero.Search();
|
||||||
|
|
|
@ -1298,9 +1298,6 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'tempTable':
|
case 'tempTable':
|
||||||
if (!condition.value.match(/^[a-zA-Z0-9]+$/)) {
|
|
||||||
throw ("Invalid temp table '" + condition.value + "'");
|
|
||||||
}
|
|
||||||
condSQL += "itemID IN (SELECT id FROM " + condition.value + ")";
|
condSQL += "itemID IN (SELECT id FROM " + condition.value + ")";
|
||||||
skipOperators = true;
|
skipOperators = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -45,31 +45,34 @@ Zotero.Duplicates.prototype.__defineGetter__('libraryID', function () { return t
|
||||||
*
|
*
|
||||||
* @return {Zotero.Search}
|
* @return {Zotero.Search}
|
||||||
*/
|
*/
|
||||||
Zotero.Duplicates.prototype.getSearchObject = Zotero.Promise.coroutine(function* () {
|
Zotero.Duplicates.prototype.getSearchObject = async function () {
|
||||||
yield Zotero.DB.executeTransaction(function* () {
|
var table = 'tmpDuplicates_' + Zotero.Utilities.randomString();
|
||||||
var sql = "DROP TABLE IF EXISTS tmpDuplicates";
|
|
||||||
yield Zotero.DB.queryAsync(sql);
|
|
||||||
|
|
||||||
var sql = "CREATE TEMPORARY TABLE tmpDuplicates "
|
await this._findDuplicates();
|
||||||
+ "(id INTEGER PRIMARY KEY)";
|
|
||||||
yield Zotero.DB.queryAsync(sql);
|
|
||||||
|
|
||||||
yield this._findDuplicates();
|
|
||||||
var ids = this._sets.findAll(true);
|
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");
|
Zotero.debug("Inserting rows into temp table");
|
||||||
sql = "INSERT INTO tmpDuplicates VALUES (?)";
|
sql = `INSERT INTO ${table} VALUES `;
|
||||||
for (let i=0; i<ids.length; i++) {
|
await Zotero.Utilities.Internal.forEachChunkAsync(
|
||||||
yield Zotero.DB.queryAsync(sql, [ids[i]], { debug: false })
|
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");
|
Zotero.debug("Done");
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
var s = new Zotero.Search;
|
var s = new Zotero.Search;
|
||||||
s.libraryID = this._libraryID;
|
s.libraryID = this._libraryID;
|
||||||
s.addCondition('tempTable', 'is', 'tmpDuplicates');
|
s.addCondition('tempTable', 'is', table);
|
||||||
return s;
|
return s;
|
||||||
});
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 = async function() {
|
||||||
*/
|
|
||||||
Zotero.ItemTreeView.prototype.unregister = function()
|
|
||||||
{
|
|
||||||
Zotero.Notifier.unregisterObserver(this._unregisterID);
|
Zotero.Notifier.unregisterObserver(this._unregisterID);
|
||||||
|
|
||||||
|
if (this.collectionTreeRow.onUnload) {
|
||||||
|
await this.collectionTreeRow.onUnload();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.listener) {
|
if (this.listener) {
|
||||||
if (!this._treebox.treeBody) {
|
if (!this._treebox.treeBody) {
|
||||||
Zotero.debug("No more tree body in Zotero.ItemTreeView::unregister()");
|
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);
|
tree.removeEventListener('keypress', this.listener, false);
|
||||||
this.listener = null;
|
this.listener = null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue