diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index 95b388ed7..5bae44685 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -664,7 +664,7 @@ Zotero.Search.prototype.search = function(asTempTable){ } // Search ids in temp table - var sql = "SELECT itemID FROM items WHERE itemID IN (" + this._sql + ") " + var sql = "SELECT GROUP_CONCAT(itemID) FROM items WHERE itemID IN (" + this._sql + ") " + "AND (" + "itemID IN (SELECT itemID FROM " + tmpTable + ")"; @@ -676,7 +676,8 @@ Zotero.Search.prototype.search = function(asTempTable){ } sql += ")"; - var ids = Zotero.DB.columnQuery(sql, this._sqlParams); + var res = Zotero.DB.valueQuery(sql, this._sqlParams), + ids = res ? res.split(",") : []; /* // DEBUG: Should this be here? // @@ -723,9 +724,10 @@ Zotero.Search.prototype.search = function(asTempTable){ var tmpTable = Zotero.Search.idsToTempTable(ids); } - var sql = "SELECT itemID FROM items WHERE " + var sql = "SELECT GROUP_CONCAT(itemID) FROM items WHERE " + "itemID NOT IN (SELECT itemID FROM " + tmpTable + ")"; - var scopeIDs = Zotero.DB.columnQuery(sql); + var res = Zotero.DB.valueQuery(sql).split(","); + var scopeIDs = res ? res.split(",") : []; } // If an ALL search, scan only items from the main search else { @@ -866,8 +868,9 @@ Zotero.Search.prototype.search = function(asTempTable){ } } - sql = "SELECT itemID FROM items WHERE itemID IN (" + sql + ")"; - var parentChildIDs = Zotero.DB.columnQuery(sql); + sql = "SELECT GROUP_CONCAT(itemID) FROM items WHERE itemID IN (" + sql + ")"; + var res = Zotero.DB.valueQuery(sql); + var parentChildIDs = res ? res.split(",") : []; Zotero.DB.query("DROP TABLE " + tmpTable); Zotero.DB.commitTransaction(); @@ -953,16 +956,26 @@ Zotero.Search.prototype._prepFieldChange = function (field) { * Batch insert */ Zotero.Search.idsToTempTable = function (ids) { + const N_COMBINED_INSERTS = 128; + var tmpTable = "tmpSearchResults_" + Zotero.randomString(8); Zotero.DB.beginTransaction(); var sql = "CREATE TEMPORARY TABLE " + tmpTable + " (itemID INT)"; Zotero.DB.query(sql); - var sql = "INSERT INTO " + tmpTable + " VALUES (?)"; - var insertStatement = Zotero.DB.getStatement(sql); - for (var i=0; i