Avoid temporary table when getting tags for current view

Instead, pass ids directly to SQLite. This seems to take about the same
amount of time or a little less (by avoiding the time it takes to start
a transaction) and avoids blocking other transactions when switching
views.
This commit is contained in:
Dan Stillman 2016-01-17 00:57:34 -05:00
parent 5ef89b1d0f
commit a80f130997
3 changed files with 25 additions and 26 deletions

View File

@ -331,8 +331,8 @@ Zotero.CollectionTreeRow.prototype.getChildTags = Zotero.Promise.coroutine(funct
case 'bucket': case 'bucket':
return false; return false;
} }
var results = yield this.getSearchResults(true); var results = yield this.getSearchResults();
return Zotero.Tags.getAllWithinSearchResults(results); return Zotero.Tags.getAllWithinItemsList(results);
}); });

View File

@ -101,37 +101,36 @@ Zotero.Tags = new function() {
* *
* @param {Zotero.Search} search * @param {Zotero.Search} search
* @param {Array} [types] Array of tag types to fetch * @param {Array} [types] Array of tag types to fetch
* @param {String|Promise<String>} [tmpTable] Temporary table with items to use * @return {Promise<Object>} Promise for object with tag data in API JSON format, keyed by tagID
*/ */
this.getAllWithinSearch = Zotero.Promise.coroutine(function* (search, types) { this.getAllWithinSearch = Zotero.Promise.coroutine(function* (search, types) {
// Save search results to temporary table, if one isn't provided var ids = yield search.search();
var tmpTable = yield search.search(true); return this.getAllWithinItemsList(ids, types);
if (!tmpTable) {
return {};
}
return this.getAllWithinSearchResults(tmpTable, types);
}); });
/** this.getAllWithinItemsList = Zotero.Promise.coroutine(function* (ids, types) {
* Get all tags within the items of a temporary table of search results if (!Array.isArray(ids)) {
* throw new Error("ids must be an array");
* @param {String} tmpTable Temporary table with items to use }
* @param {Array} [types] Array of tag types to fetch if (!ids.length) {
* @return {Promise<Object>} Promise for object with tag data in API JSON format, keyed by tagID return {};
*/
this.getAllWithinSearchResults = Zotero.Promise.coroutine(function* (tmpTable, types) {
var sql = "SELECT DISTINCT name AS tag, type FROM itemTags "
+ "JOIN tags USING (tagID) WHERE itemID IN "
+ "(SELECT itemID FROM " + tmpTable + ") ";
if (types) {
sql += "AND type IN (" + types.join() + ") ";
} }
var rows = yield Zotero.DB.queryAsync(sql);
if(!tmpTable) { var prefix = "SELECT DISTINCT name AS tag, type FROM itemTags "
yield Zotero.DB.queryAsync("DROP TABLE " + tmpTable); + "JOIN tags USING (tagID) WHERE itemID IN "
+ "(";
var suffix = ") ";
if (types) {
suffix += "AND type IN (" + types.join() + ") ";
} }
// Don't include ids in debug output
Zotero.DB.logQuery(`${prefix}[...${ids.length}]${suffix}`);
var rows = yield Zotero.DB.queryAsync(
prefix + ids.map(id => parseInt(id)).join(",") + suffix,
false,
{ debug: false }
);
return rows.map((row) => this.cleanData(row)); return rows.map((row) => this.cleanData(row));
}); });

View File

@ -776,7 +776,7 @@ Zotero.DBConnection.prototype.columnQueryAsync = Zotero.Promise.coroutine(functi
}); });
Zotero.DBConnection.prototype.logQuery = function (sql, params, options) { Zotero.DBConnection.prototype.logQuery = function (sql, params = [], options) {
if (options && options.debug === false) return; if (options && options.debug === false) return;
var msg = sql; var msg = sql;
if (params.length) { if (params.length) {