From 912801a34951a77bbfc56d1d69bd4fc8b106423b Mon Sep 17 00:00:00 2001 From: TheNEwmanator15 <3686761+Thenewmanator15@users.noreply.github.com> Date: Fri, 25 Sep 2026 00:11:48 +0100 Subject: [PATCH] Load creators and primary data with less per-row work - _loadCreators(): read columns by index in onRow as rows arrive instead of materializing every item/creator row as a Proxy, whose property reads each go through getResultByName() - _loadPrimaryData(): compute the column list and ID column once per query rather than once per row - ItemFields._getLoadInfo(): index the cache with arrays instead of a Map Co-Authored-By: Claude Opus 5.5 --- .../content/zotero/xpcom/data/dataObjects.js | 7 +- .../content/zotero/xpcom/data/itemFields.js | 6 +- chrome/content/zotero/xpcom/data/items.js | 75 ++++++++++--------- 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js index 3e5726602d..414d438f05 100644 --- a/chrome/content/zotero/xpcom/data/dataObjects.js +++ b/chrome/content/zotero/xpcom/data/dataObjects.js @@ -555,14 +555,17 @@ Zotero.DataObjects.prototype._loadPrimaryData = async function (libraryID, ids, sql += ' AND O.' + this._ZDO_id + ' IN (' + ids.join(',') + ')'; } + var columns = Object.keys(this._primaryDataSQLParts); + var idColumn = columns.indexOf(this._ZDO_id); await Zotero.DB.queryAsync( sql, params, { noCache: true, onRow: function (row) { - var id = row.getResultByName(this._ZDO_id); - var columns = Object.keys(this._primaryDataSQLParts); + var id = idColumn != -1 + ? row.getResultByIndex(idColumn) + : row.getResultByName(this._ZDO_id); var rowObj = {}; for (let i=0; i { + let itemID = row.getResultByIndex(0); + let creatorID = row.getResultByIndex(1); - item._creators = []; - item._creatorIDs = []; - item._loaded.creators = true; - item._clearChanged('creators'); - - if (!row.creatorID) { - lastItemID = row.itemID; - continue; + if (itemID != lastItemID) { + if (!this._objectCache[itemID]) { + throw new Error("Item " + itemID + " not loaded"); + } + item = this._objectCache[itemID]; + + item._creators = []; + item._creatorIDs = []; + item._loaded.creators = true; + item._clearChanged('creators'); + + if (!creatorID) { + lastItemID = itemID; + return; + } + + if (index <= maxOrderIndex) { + fixIncorrectIndexes(item, index, maxOrderIndex); + } + + index = 0; + maxOrderIndex = -1; } - if (index <= maxOrderIndex) { - fixIncorrectIndexes(item, index, maxOrderIndex); + lastItemID = itemID; + + let orderIndex = row.getResultByIndex(3); + if (orderIndex > maxOrderIndex) { + maxOrderIndex = orderIndex; } - index = 0; - maxOrderIndex = -1; + let creatorData = Zotero.Creators.get(creatorID); + creatorData.creatorTypeID = row.getResultByIndex(2); + item._creators[index] = creatorData; + item._creatorIDs[index] = creatorID; + index++; } - - lastItemID = row.itemID; - - if (row.orderIndex > maxOrderIndex) { - maxOrderIndex = row.orderIndex; - } - - let creatorData = Zotero.Creators.get(row.creatorID); - creatorData.creatorTypeID = row.creatorTypeID; - item._creators[index] = creatorData; - item._creatorIDs[index] = row.creatorID; - index++; - } + }); if (index <= maxOrderIndex) { fixIncorrectIndexes(item, index, maxOrderIndex);