www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit a80f1309974e5e36e9d7bd96c5e54414e0961282
parent 5ef89b1d0f772803d11a727d30b95ee81de70e1e
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun, 17 Jan 2016 00:57:34 -0500

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.

Diffstat:
Mchrome/content/zotero/xpcom/collectionTreeRow.js | 4++--
Mchrome/content/zotero/xpcom/data/tags.js | 47+++++++++++++++++++++++------------------------
Mchrome/content/zotero/xpcom/db.js | 2+-
3 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/chrome/content/zotero/xpcom/collectionTreeRow.js b/chrome/content/zotero/xpcom/collectionTreeRow.js @@ -331,8 +331,8 @@ Zotero.CollectionTreeRow.prototype.getChildTags = Zotero.Promise.coroutine(funct case 'bucket': return false; } - var results = yield this.getSearchResults(true); - return Zotero.Tags.getAllWithinSearchResults(results); + var results = yield this.getSearchResults(); + return Zotero.Tags.getAllWithinItemsList(results); }); diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js @@ -101,38 +101,37 @@ Zotero.Tags = new function() { * * @param {Zotero.Search} search * @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) { - // Save search results to temporary table, if one isn't provided - var tmpTable = yield search.search(true); - if (!tmpTable) { - return {}; - } - return this.getAllWithinSearchResults(tmpTable, types); + var ids = yield search.search(); + return this.getAllWithinItemsList(ids, types); }); - /** - * Get all tags within the items of a temporary table of search results - * - * @param {String} tmpTable Temporary table with items to use - * @param {Array} [types] Array of tag types to fetch - * @return {Promise<Object>} Promise for object with tag data in API JSON format, keyed by tagID - */ - 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() + ") "; + this.getAllWithinItemsList = Zotero.Promise.coroutine(function* (ids, types) { + if (!Array.isArray(ids)) { + throw new Error("ids must be an array"); } - var rows = yield Zotero.DB.queryAsync(sql); - - if(!tmpTable) { - yield Zotero.DB.queryAsync("DROP TABLE " + tmpTable); + if (!ids.length) { + return {}; } + var prefix = "SELECT DISTINCT name AS tag, type FROM itemTags " + + "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)); }); diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js @@ -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; var msg = sql; if (params.length) {