- More efficient purging logic -- instead of purging all objects whenever an item is deleted, flag just the object type and do the necessary purge when the Zotero pane is next opened. This also fixes a sync error edge case due to purging during synced item deletions.

- Disable unresponsive script warning during items list refresh
- Zotero.UnresponsiveScriptIndicator.disable() now returns true if it disables the indicator and false if it was already disabled
This commit is contained in:
Dan Stillman 2009-02-18 03:09:39 +00:00
parent 8233e54ea1
commit 26e6125450
11 changed files with 98 additions and 27 deletions

View file

@ -338,6 +338,11 @@ var ZoteroPane = new function()
// Focus the quicksearch on pane open // Focus the quicksearch on pane open
setTimeout("document.getElementById('zotero-tb-search').inputField.select();", 1); setTimeout("document.getElementById('zotero-tb-search').inputField.select();", 1);
var d = new Date();
Zotero.purgeDataObjects(true);
var d2 = new Date();
Zotero.debug("Purged data tables in " + (d2 - d) + "ms");
if (Zotero.Prefs.get('sync.autoSync') && Zotero.Sync.Server.enabled) { if (Zotero.Prefs.get('sync.autoSync') && Zotero.Sync.Server.enabled) {
setTimeout(function () { setTimeout(function () {
Zotero.Sync.Runner.sync(); Zotero.Sync.Runner.sync();

View file

@ -409,6 +409,8 @@ Zotero.Creator.prototype.erase = function () {
} }
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero.Prefs.set('purge.creators', true);
} }

View file

@ -197,6 +197,10 @@ Zotero.Creators = new function() {
* and clear internal array entries * and clear internal array entries
*/ */
function purge() { function purge() {
if (!Zotero.Prefs.get('purge.creators')) {
return;
}
Zotero.debug("Purging creator tables"); Zotero.debug("Purging creator tables");
// Purge unused creators // Purge unused creators
@ -230,6 +234,8 @@ Zotero.Creators = new function() {
+ "(SELECT creatorDataID FROM creators)"; + "(SELECT creatorDataID FROM creators)";
Zotero.DB.query(sql); Zotero.DB.query(sql);
} }
Zotero.Prefs.set('purge.creators', false);
} }

View file

@ -3358,7 +3358,12 @@ Zotero.Item.prototype.erase = function(deleteChildren) {
Zotero.DB.query('DELETE FROM annotations WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM annotations WHERE itemID=?', this.id);
Zotero.DB.query('DELETE FROM highlights WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM highlights WHERE itemID=?', this.id);
Zotero.DB.query('DELETE FROM deletedItems WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM deletedItems WHERE itemID=?', this.id);
var hasCreators = Zotero.DB.valueQuery(
"SELECT rowid FROM itemCreators WHERE itemID=? LIMIT 1", this.id
);
if (hasCreators) {
Zotero.DB.query('DELETE FROM itemCreators WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM itemCreators WHERE itemID=?', this.id);
}
Zotero.DB.query('DELETE FROM itemNotes WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM itemNotes WHERE itemID=?', this.id);
Zotero.DB.query('DELETE FROM itemAttachments WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM itemAttachments WHERE itemID=?', this.id);
Zotero.DB.query('DELETE FROM itemSeeAlso WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM itemSeeAlso WHERE itemID=?', this.id);
@ -3392,6 +3397,11 @@ Zotero.Item.prototype.erase = function(deleteChildren) {
} }
Zotero.Notifier.trigger('delete', 'item', this.id, deletedItemNotifierData); Zotero.Notifier.trigger('delete', 'item', this.id, deletedItemNotifierData);
Zotero.Prefs.set('purge.items', true);
if (hasCreators) {
Zotero.Prefs.set('purge.creators', true);
}
} }

View file

@ -35,7 +35,6 @@ Zotero.Items = new function() {
this.add = add; this.add = add;
this.cacheFields = cacheFields; this.cacheFields = cacheFields;
this.erase = erase; this.erase = erase;
this.purge = purge;
this.getFirstCreatorSQL = getFirstCreatorSQL; this.getFirstCreatorSQL = getFirstCreatorSQL;
this.getSortTitle = getSortTitle; this.getSortTitle = getSortTitle;
@ -386,7 +385,7 @@ Zotero.Items = new function() {
function erase(ids, eraseChildren) { function erase(ids, eraseChildren) {
ids = Zotero.flattenArguments(ids); ids = Zotero.flattenArguments(ids);
Zotero.UnresponsiveScriptIndicator.disable(); var usiDisabled = Zotero.UnresponsiveScriptIndicator.disable();
try { try {
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
for each(var id in ids) { for each(var id in ids) {
@ -399,7 +398,6 @@ Zotero.Items = new function() {
item.erase(eraseChildren); // calls unload() item.erase(eraseChildren); // calls unload()
item = undefined; item = undefined;
} }
this.purge();
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
} }
catch (e) { catch (e) {
@ -407,31 +405,26 @@ Zotero.Items = new function() {
throw (e); throw (e);
} }
finally { finally {
if (usiDisabled) {
Zotero.UnresponsiveScriptIndicator.enable(); Zotero.UnresponsiveScriptIndicator.enable();
} }
} }
}
/* /**
* Clear entries from various tables that no longer exist * Purge unused data values
*
* This is called automatically by Items.erase() but must be called
* manually after Item.erase()
*/ */
function purge() { this.purge = function () {
Zotero.Creators.purge(); if (!Zotero.Prefs.get('purge.items')) {
Zotero.Tags.purge(); return;
Zotero.Fulltext.purgeUnusedWords(); }
// Purge unused values
var sql = "DELETE FROM itemDataValues WHERE valueID NOT IN " var sql = "DELETE FROM itemDataValues WHERE valueID NOT IN "
+ "(SELECT valueID FROM itemData)"; + "(SELECT valueID FROM itemData)";
Zotero.DB.query(sql); Zotero.DB.query(sql);
var ZU = new Zotero.Utilities; Zotero.Prefs.set('purge.items', false)
if (Zotero.Sync.Storage.active && ZU.probability(10)) {
Zotero.Sync.Storage.purgeDeletedStorageFiles();
}
} }

View file

@ -531,6 +531,8 @@ Zotero.Tag.prototype.erase = function () {
Zotero.Notifier.trigger('delete', 'tag', this.id, deletedTagNotifierData); Zotero.Notifier.trigger('delete', 'tag', this.id, deletedTagNotifierData);
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero.Prefs.set('purge.tags', true);
return; return;
} }

View file

@ -342,13 +342,17 @@ Zotero.Tags = new function() {
* Returns removed tagIDs on success * Returns removed tagIDs on success
*/ */
function purge() { function purge() {
if (!Zotero.Prefs.get('purge.tags')) {
return;
}
Zotero.UnresponsiveScriptIndicator.disable(); Zotero.UnresponsiveScriptIndicator.disable();
try { try {
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
var sql = "CREATE TEMPORARY TABLE tagDelete AS " var sql = "CREATE TEMPORARY TABLE tagDelete AS "
+ "SELECT tagID FROM tags WHERE tagID " + "SELECT tagID FROM tags WHERE tagID "
+ "NOT IN (SELECT tagID FROM itemTags);"; + "NOT IN (SELECT tagID FROM itemTags)";
Zotero.DB.query(sql); Zotero.DB.query(sql);
sql = "CREATE INDEX tagDelete_tagID ON tagDelete(tagID)"; sql = "CREATE INDEX tagDelete_tagID ON tagDelete(tagID)";
@ -361,6 +365,7 @@ Zotero.Tags = new function() {
sql = "DROP TABLE tagDelete"; sql = "DROP TABLE tagDelete";
Zotero.DB.query(sql); Zotero.DB.query(sql);
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero.Prefs.set('purge.tags', false);
return; return;
} }
@ -393,6 +398,8 @@ Zotero.Tags = new function() {
finally { finally {
Zotero.UnresponsiveScriptIndicator.enable(); Zotero.UnresponsiveScriptIndicator.enable();
} }
Zotero.Prefs.set('purge.tags', false);
} }

View file

@ -634,10 +634,18 @@ Zotero.Fulltext = new function(){
function clearItemWords(itemID){ function clearItemWords(itemID){
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
Zotero.DB.query("DELETE FROM fulltextItems WHERE itemID=" + itemID); var sql = "SELECT rowid FROM fulltextItems WHERE itemID=? LIMIT 1";
Zotero.DB.query("DELETE FROM fulltextItemWords WHERE itemID=" + itemID); var indexed = Zotero.DB.valueQuery(sql, itemID);
if (indexed) {
Zotero.DB.query("DELETE FROM fulltextItems WHERE itemID=?", itemID);
Zotero.DB.query("DELETE FROM fulltextItemWords WHERE itemID=?", itemID);
}
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
if (indexed) {
Zotero.Prefs.set('purge.fulltext', true);
}
// Delete fulltext cache file if there is one // Delete fulltext cache file if there is one
this.clearCacheFile(itemID); this.clearCacheFile(itemID);
} }
@ -933,10 +941,16 @@ Zotero.Fulltext = new function(){
*/ */
function purgeUnusedWords(){ function purgeUnusedWords() {
if (!Zotero.Prefs.get('purge.fulltext')) {
return;
}
var sql = "DELETE FROM fulltextWords WHERE wordID NOT IN " var sql = "DELETE FROM fulltextWords WHERE wordID NOT IN "
+ "(SELECT wordID FROM fulltextItemWords)"; + "(SELECT wordID FROM fulltextItemWords)";
Zotero.DB.query(sql); Zotero.DB.query(sql);
Zotero.Prefs.set('purge.fulltext', false)
} }

View file

@ -155,6 +155,9 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
Zotero.ItemTreeView.prototype.refresh = function() Zotero.ItemTreeView.prototype.refresh = function()
{ {
Zotero.debug('Refreshing items list'); Zotero.debug('Refreshing items list');
var usiDisabled = Zotero.UnresponsiveScriptIndicator.disable();
this._searchMode = this._itemGroup.isSearchMode(); this._searchMode = this._itemGroup.isSearchMode();
var oldRows = this.rowCount; var oldRows = this.rowCount;
@ -228,6 +231,10 @@ Zotero.ItemTreeView.prototype.refresh = function()
if (diff != 0) { if (diff != 0) {
this._treebox.rowCountChanged(0, diff); this._treebox.rowCountChanged(0, diff);
} }
if (usiDisabled) {
Zotero.UnresponsiveScriptIndicator.enable();
}
} }

View file

@ -970,6 +970,22 @@ var Zotero = new function(){
} }
/*
* Clear entries that no longer exist from various tables
*/
this.purgeDataObjects = function () {
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)) {
Zotero.Sync.Storage.purgeDeletedStorageFiles();
}
}
function reloadDataObjects() { function reloadDataObjects() {
Zotero.Tags.reloadAll(); Zotero.Tags.reloadAll();
Zotero.Collections.reloadAll(); Zotero.Collections.reloadAll();
@ -2103,7 +2119,9 @@ Zotero.UnresponsiveScriptIndicator = new function() {
**/ **/
function disable() { function disable() {
// don't do anything if already disabled // don't do anything if already disabled
if(_isDisabled) return; if (_isDisabled) {
return false;
}
var prefService = Components.classes["@mozilla.org/preferences-service;1"]. var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch); getService(Components.interfaces.nsIPrefBranch);
@ -2111,6 +2129,7 @@ Zotero.UnresponsiveScriptIndicator = new function() {
prefService.setIntPref("dom.max_chrome_script_run_time", 0); prefService.setIntPref("dom.max_chrome_script_run_time", 0);
_isDisabled = true; _isDisabled = true;
return true;
} }
/** /**

View file

@ -103,3 +103,9 @@ pref("extensions.zotero.sync.storage.deleteDelayDays", 30);
// Proxy // Proxy
pref("extensions.zotero.proxies.autoRecognize", true); pref("extensions.zotero.proxies.autoRecognize", true);
pref("extensions.zotero.proxies.transparent", true); pref("extensions.zotero.proxies.transparent", true);
// Data layer purging
pref("extensions.zotero.purge.creators", false);
pref("extensions.zotero.purge.fulltext", false);
pref("extensions.zotero.purge.items", false);
pref("extensions.zotero.purge.tags", false);