Close #945, Optimize bulk reload on multi-item changes

This commit is contained in:
Dan Stillman 2016-05-16 18:25:35 -04:00
parent 56dcd6da26
commit 6f04b34d59

View file

@ -654,9 +654,32 @@ Zotero.DataObjects.prototype.reload = Zotero.Promise.coroutine(function* (ids, d
Zotero.debug('Reloading ' + (dataTypes ? '[' + dataTypes.join(', ') + '] for ' : '') Zotero.debug('Reloading ' + (dataTypes ? '[' + dataTypes.join(', ') + '] for ' : '')
+ this._ZDO_objects + ' ' + ids); + this._ZDO_objects + ' ' + ids);
for (let i=0; i<ids.length; i++) { // If data types not specified, reload loaded data for each object individually.
if (this._objectCache[ids[i]]) { // TODO: optimize
yield this._objectCache[ids[i]].reload(dataTypes, reloadUnchanged); if (!dataTypes) {
for (let i=0; i<ids.length; i++) {
if (this._objectCache[ids[i]]) {
yield this._objectCache[ids[i]].reload(dataTypes, reloadUnchanged);
}
}
return;
}
for (let dataType of dataTypes) {
let typeIDsByLibrary = {};
for (let id of ids) {
let obj = this._objectCache[id];
if (!obj || !obj._loaded[dataType] || obj._skipDataTypeLoad[dataType]
|| (!reloadUnchanged && !obj._changed[dataType])) {
continue;
}
if (!typeIDsByLibrary[obj.libraryID]) {
typeIDsByLibrary[obj.libraryID] = [];
}
typeIDsByLibrary[obj.libraryID].push(id);
}
for (let libraryID in typeIDsByLibrary) {
yield this._loadDataType(dataType, parseInt(libraryID), typeIDsByLibrary[libraryID]);
} }
} }