Proper updating of cached parent collections
This commit is contained in:
parent
0fb1d5866f
commit
4450e12152
|
@ -179,12 +179,6 @@ Zotero.Collection.prototype.hasChildItems = function() {
|
||||||
return !!(parseInt(this._hasChildItems));
|
return !!(parseInt(this._hasChildItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Collection.prototype.refreshChildCollections = function () {
|
|
||||||
this._hasChildCollections = undefined;
|
|
||||||
this._childCollectionsLoaded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if collection exists in the database
|
* Check if collection exists in the database
|
||||||
*
|
*
|
||||||
|
@ -319,7 +313,12 @@ Zotero.Collection.prototype.save = function () {
|
||||||
Zotero.Collections.unload(oldID);
|
Zotero.Collections.unload(oldID);
|
||||||
Zotero.Notifier.trigger('id-change', 'collection', oldID + '-' + this.id);
|
Zotero.Notifier.trigger('id-change', 'collection', oldID + '-' + this.id);
|
||||||
|
|
||||||
// update caches
|
// Update child collections that have cached the previous id
|
||||||
|
var sql = "SELECT collectionID FROM collections WHERE parentCollectionID=?";
|
||||||
|
var children = Zotero.DB.columnQuery(sql, this.id);
|
||||||
|
if (children) {
|
||||||
|
Zotero.Collections.refreshParents(children);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isNew = !this.id || !this.exists();
|
var isNew = !this.id || !this.exists();
|
||||||
|
@ -510,12 +509,9 @@ Zotero.Collection.prototype.save = function () {
|
||||||
Zotero.Notifier.trigger('modify', 'collection', this.id, this._previousData);
|
Zotero.Notifier.trigger('modify', 'collection', this.id, this._previousData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh child collection counts
|
// Invalidate cached child collections
|
||||||
if (parentIDs) {
|
if (parentIDs) {
|
||||||
for each(var id in parentIDs) {
|
Zotero.Collections.refreshChildCollections(parentIDs)
|
||||||
var col = Zotero.Collections.get(id);
|
|
||||||
col.refreshChildCollections();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.id;
|
return this.id;
|
||||||
|
@ -982,6 +978,35 @@ Zotero.Collection.prototype._loadChildItems = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: This is called by Zotero.Collections.refreshParent()
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
Zotero.Collection.prototype._refreshParent = function () {
|
||||||
|
if (!this.id) {
|
||||||
|
throw ("Cannot call Zotero.Collection._refreshParent() on unsaved collection");
|
||||||
|
}
|
||||||
|
|
||||||
|
var sql = "SELECT parentCollectionID FROM collections "
|
||||||
|
+ "WHERE collectionID=?";
|
||||||
|
this._parent = Zotero.DB.valueQuery(sql, this.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalid child collection cache
|
||||||
|
*
|
||||||
|
* Note: This is called by Zotero.Collections.refreshChildCollections()
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
Zotero.Collection.prototype._refreshChildCollections = function () {
|
||||||
|
this._hasChildCollections = undefined;
|
||||||
|
this._childCollectionsLoaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Zotero.Collection.prototype._generateKey = function () {
|
Zotero.Collection.prototype._generateKey = function () {
|
||||||
return Zotero.ID.getKey();
|
return Zotero.ID.getKey();
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,40 @@ Zotero.Collections = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh cached parents in specified collections, skipping
|
||||||
|
* any that aren't loaded
|
||||||
|
*
|
||||||
|
* @param {Integer|Integer[]} ids One or more itemIDs
|
||||||
|
*/
|
||||||
|
this.refreshParents = function (ids) {
|
||||||
|
ids = Zotero.flattenArguments(ids);
|
||||||
|
|
||||||
|
for each(var id in ids) {
|
||||||
|
if (_collections[id]) {
|
||||||
|
_collections[id]._refreshParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate child collection cache in specified collections, skipping
|
||||||
|
* any that aren't loaded
|
||||||
|
*
|
||||||
|
* @param {Integer|Integer[]} ids One or more itemIDs
|
||||||
|
*/
|
||||||
|
this.refreshChildCollections = function (ids) {
|
||||||
|
ids = Zotero.flattenArguments(ids);
|
||||||
|
|
||||||
|
for each(var id in ids) {
|
||||||
|
if (_collections[id]) {
|
||||||
|
_collections[id]._refreshChildCollections();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function reload(id) {
|
function reload(id) {
|
||||||
if (!_collectionsLoaded) {
|
if (!_collectionsLoaded) {
|
||||||
this.reloadAll();
|
this.reloadAll();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user