www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit b76fdd8e43a26e10125b26e5febdcfb038ee3836
parent 7a195b838873338c5fda0b1474b7ea2a64172498
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 24 Apr 2009 06:16:19 +0000

Set tag/creator purge flag on removals from items, and run purge on sync


Diffstat:
Mchrome/content/zotero/overlay.js | 2+-
Mchrome/content/zotero/xpcom/data/item.js | 12+++++++++++-
Mchrome/content/zotero/xpcom/data/tag.js | 6+++++-
Mchrome/content/zotero/xpcom/sync.js | 3+++
Mchrome/content/zotero/xpcom/zotero.js | 5++---
5 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js @@ -346,7 +346,7 @@ var ZoteroPane = new function() setTimeout("document.getElementById('zotero-tb-search').inputField.select();", 1); var d = new Date(); - Zotero.purgeDataObjects(true); + Zotero.purgeDataObjects(); var d2 = new Date(); Zotero.debug("Purged data tables in " + (d2 - d) + " ms"); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -908,11 +908,16 @@ Zotero.Item.prototype.removeCreator = function(orderIndex) { this._loadCreators(); } - if (!this._creators[orderIndex]) { + var creator = this.getCreator(orderIndex); + if (!creator) { throw ('No creator exists at position ' + orderIndex + ' in Zotero.Item.removeCreator()'); } + if (creator.ref.countLinkedItems() == 1) { + Zotero.Prefs.set('purge.creators', true); + } + // Shift creator orderIndexes down, going to length+1 so we clear the last one for (var i=orderIndex, max=this._creators.length+1; i<max; i++) { var next = this._creators[i+1] ? this._creators[i+1] : false; @@ -928,6 +933,7 @@ Zotero.Item.prototype.removeCreator = function(orderIndex) { } this._changedCreators[i] = true; } + return true; } @@ -2982,6 +2988,10 @@ Zotero.Item.prototype.removeTag = function(tagID) { tag.removeItem(this.id); tag.save(); + + if (!tag.countLinkedItems()) { + Zotero.Prefs.set('purge.tags', true); + } } Zotero.Item.prototype.removeAllTags = function() { diff --git a/chrome/content/zotero/xpcom/data/tag.js b/chrome/content/zotero/xpcom/data/tag.js @@ -177,6 +177,11 @@ Zotero.Tag.prototype.getLinkedItems = function (asIDs) { } +Zotero.Tag.prototype.countLinkedItems = function () { + return this.getLinkedItems().length; +} + + Zotero.Tag.prototype.addItem = function (itemID) { var current = this.getLinkedItems(true); if (current && current.indexOf(itemID) != -1) { @@ -536,7 +541,6 @@ Zotero.Tag.prototype.erase = function () { Zotero.DB.commitTransaction(); Zotero.Prefs.set('purge.tags', true); - return; } diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js @@ -389,6 +389,9 @@ Zotero.Sync.Runner = new function () { throw ("Sync already running in Zotero.Sync.Runner.sync()"); } + // Purge deleted objects so they don't cause sync errors (e.g., long tags) + Zotero.purgeDataObjects(true); + _background = !!background; _queue = [ diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -974,14 +974,13 @@ var Zotero = new function(){ /* * Clear entries that no longer exist from various tables */ - this.purgeDataObjects = function () { + this.purgeDataObjects = function (skipStoragePurge) { Zotero.Creators.purge(); Zotero.Tags.purge(); Zotero.Fulltext.purgeUnusedWords(); Zotero.Items.purge(); - var ZU = new Zotero.Utilities; - if (Zotero.Sync.Storage.active && ZU.probability(10)) { + if (!skipStoragePurge && Zotero.Sync.Storage.active && Zotero.Utilities.prototype.probability(10)) { Zotero.Sync.Storage.purgeDeletedStorageFiles(); } }