From fbf2fbe0c610bae7d23b13ae7dd115a908b51b55 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 11 Nov 2017 02:56:27 -0500 Subject: [PATCH] Fix extremely slow tag query with some SQLite databases Reverts a80f13099, "Avoid temporary table when getting tags for current view", fixes a couple things, and removes the unused Zotero.Tags.getAllWithinSearch(). Fixes #1290 --- .../content/zotero/xpcom/collectionTreeRow.js | 4 +- chrome/content/zotero/xpcom/data/tags.js | 37 ++++--------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeRow.js b/chrome/content/zotero/xpcom/collectionTreeRow.js index a056b8c1a..07068df97 100644 --- a/chrome/content/zotero/xpcom/collectionTreeRow.js +++ b/chrome/content/zotero/xpcom/collectionTreeRow.js @@ -381,8 +381,8 @@ Zotero.CollectionTreeRow.prototype.getChildTags = Zotero.Promise.coroutine(funct case 'bucket': return []; } - var results = yield this.getSearchResults(); - return Zotero.Tags.getAllWithinItemsList(results); + var results = yield this.getSearchResults(true); + return Zotero.Tags.getAllWithinSearchResults(results); }); diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index a3ae45476..24adff6be 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -154,41 +154,20 @@ Zotero.Tags = new function() { /** - * Get all tags within the items of a Zotero.Search object + * Get all tags within the items of a temporary table of search results * - * @param {Zotero.Search} search - * @param {Array} [types] Array of tag types to fetch + * @param {String} tmpTable Temporary table with items to use + * @param {Array} [types] Array of tag types to fetch * @return {Promise} Promise for object with tag data in API JSON format, keyed by tagID */ - this.getAllWithinSearch = Zotero.Promise.coroutine(function* (search, types) { - var ids = yield search.search(); - return this.getAllWithinItemsList(ids, types); - }); - - - this.getAllWithinItemsList = Zotero.Promise.coroutine(function* (ids, types) { - if (!Array.isArray(ids)) { - throw new Error("ids must be an array"); - } - if (!ids.length) { - return []; - } - - var prefix = "SELECT DISTINCT name AS tag, type FROM itemTags " + 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 " - + "("; - var suffix = ") "; + + "(SELECT itemID FROM " + tmpTable + ") "; if (types) { - suffix += "AND type IN (" + types.join() + ") "; + sql += "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 } - ); - + var rows = yield Zotero.DB.queryAsync(sql); return rows.map((row) => this.cleanData(row)); });