commit c982155f21288fecee7b3188c83cb3a0af217eff
parent 030f918e22c6d8734423c442e10e524ab35332ae
Author: Simon Kornblith <simon@simonster.com>
Date: Sun, 25 Sep 2011 23:06:48 +0000
10-20% speed boost in initial itemTreeView load
Diffstat:
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js
@@ -49,6 +49,11 @@ Zotero.Items = new function() {
['firstCreator', 'numNotes', 'numAttachments']
);
}
+
+ // Once primary fields have been cached, get rid of getter for speed purposes
+ delete this.primaryFields;
+ this.primaryFields = _primaryFields;
+
return _primaryFields;
});
@@ -685,28 +690,29 @@ Zotero.Items = new function() {
if (arguments[0]) {
sql += ' AND I.itemID IN (' + Zotero.join(arguments[0], ',') + ')';
}
- var itemsRows = Zotero.DB.query(sql);
- var itemIDs = [];
- for each(var row in itemsRows) {
- var itemID = row.itemID;
- itemIDs.push(itemID);
+ var itemsRows = Zotero.DB.query(sql),
+ itemIDs = {};
+ for(var i=0, n=itemsRows.length; i<n; i++) {
+ var row = itemsRows[i],
+ itemID = row.itemID;
+ itemIDs[itemID] = true;
// Item doesn't exist -- create new object and stuff in array
- if (!this._objectCache[row.itemID]) {
+ if (!this._objectCache[itemID]) {
var item = new Zotero.Item();
item.loadFromRow(row, true);
- this._objectCache[row.itemID] = item;
+ this._objectCache[itemID] = item;
}
// Existing item -- reload in place
else {
- this._objectCache[row.itemID].loadFromRow(row, true);
+ this._objectCache[itemID].loadFromRow(row, true);
}
}
// If loading all items, remove old items that no longer exist
if (!arguments[0]) {
for each(var c in this._objectCache) {
- if (itemIDs.indexOf(c.id) == -1) {
+ if (!itemIDs[c.id]) {
this.unload(c.id);
}
}