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.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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue