- 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:
parent
8233e54ea1
commit
26e6125450
11 changed files with 98 additions and 27 deletions
|
@ -338,6 +338,11 @@ var ZoteroPane = new function()
|
|||
// Focus the quicksearch on pane open
|
||||
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) {
|
||||
setTimeout(function () {
|
||||
Zotero.Sync.Runner.sync();
|
||||
|
|
|
@ -409,6 +409,8 @@ Zotero.Creator.prototype.erase = function () {
|
|||
}
|
||||
|
||||
Zotero.DB.commitTransaction();
|
||||
|
||||
Zotero.Prefs.set('purge.creators', true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -197,6 +197,10 @@ Zotero.Creators = new function() {
|
|||
* and clear internal array entries
|
||||
*/
|
||||
function purge() {
|
||||
if (!Zotero.Prefs.get('purge.creators')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.debug("Purging creator tables");
|
||||
|
||||
// Purge unused creators
|
||||
|
@ -230,6 +234,8 @@ Zotero.Creators = new function() {
|
|||
+ "(SELECT creatorDataID FROM creators)";
|
||||
Zotero.DB.query(sql);
|
||||
}
|
||||
|
||||
Zotero.Prefs.set('purge.creators', false);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 highlights 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 itemNotes WHERE itemID=?', this.id);
|
||||
Zotero.DB.query('DELETE FROM itemAttachments 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.Prefs.set('purge.items', true);
|
||||
if (hasCreators) {
|
||||
Zotero.Prefs.set('purge.creators', true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ Zotero.Items = new function() {
|
|||
this.add = add;
|
||||
this.cacheFields = cacheFields;
|
||||
this.erase = erase;
|
||||
this.purge = purge;
|
||||
this.getFirstCreatorSQL = getFirstCreatorSQL;
|
||||
this.getSortTitle = getSortTitle;
|
||||
|
||||
|
@ -386,7 +385,7 @@ Zotero.Items = new function() {
|
|||
function erase(ids, eraseChildren) {
|
||||
ids = Zotero.flattenArguments(ids);
|
||||
|
||||
Zotero.UnresponsiveScriptIndicator.disable();
|
||||
var usiDisabled = Zotero.UnresponsiveScriptIndicator.disable();
|
||||
try {
|
||||
Zotero.DB.beginTransaction();
|
||||
for each(var id in ids) {
|
||||
|
@ -399,7 +398,6 @@ Zotero.Items = new function() {
|
|||
item.erase(eraseChildren); // calls unload()
|
||||
item = undefined;
|
||||
}
|
||||
this.purge();
|
||||
Zotero.DB.commitTransaction();
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -407,31 +405,26 @@ Zotero.Items = new function() {
|
|||
throw (e);
|
||||
}
|
||||
finally {
|
||||
if (usiDisabled) {
|
||||
Zotero.UnresponsiveScriptIndicator.enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Clear entries from various tables that no longer exist
|
||||
*
|
||||
* This is called automatically by Items.erase() but must be called
|
||||
* manually after Item.erase()
|
||||
/**
|
||||
* Purge unused data values
|
||||
*/
|
||||
function purge() {
|
||||
Zotero.Creators.purge();
|
||||
Zotero.Tags.purge();
|
||||
Zotero.Fulltext.purgeUnusedWords();
|
||||
this.purge = function () {
|
||||
if (!Zotero.Prefs.get('purge.items')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Purge unused values
|
||||
var sql = "DELETE FROM itemDataValues WHERE valueID NOT IN "
|
||||
+ "(SELECT valueID FROM itemData)";
|
||||
Zotero.DB.query(sql);
|
||||
|
||||
var ZU = new Zotero.Utilities;
|
||||
if (Zotero.Sync.Storage.active && ZU.probability(10)) {
|
||||
Zotero.Sync.Storage.purgeDeletedStorageFiles();
|
||||
}
|
||||
Zotero.Prefs.set('purge.items', false)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -531,6 +531,8 @@ Zotero.Tag.prototype.erase = function () {
|
|||
Zotero.Notifier.trigger('delete', 'tag', this.id, deletedTagNotifierData);
|
||||
|
||||
Zotero.DB.commitTransaction();
|
||||
|
||||
Zotero.Prefs.set('purge.tags', true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -342,13 +342,17 @@ Zotero.Tags = new function() {
|
|||
* Returns removed tagIDs on success
|
||||
*/
|
||||
function purge() {
|
||||
if (!Zotero.Prefs.get('purge.tags')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.UnresponsiveScriptIndicator.disable();
|
||||
try {
|
||||
Zotero.DB.beginTransaction();
|
||||
|
||||
var sql = "CREATE TEMPORARY TABLE tagDelete AS "
|
||||
+ "SELECT tagID FROM tags WHERE tagID "
|
||||
+ "NOT IN (SELECT tagID FROM itemTags);";
|
||||
+ "NOT IN (SELECT tagID FROM itemTags)";
|
||||
Zotero.DB.query(sql);
|
||||
|
||||
sql = "CREATE INDEX tagDelete_tagID ON tagDelete(tagID)";
|
||||
|
@ -361,6 +365,7 @@ Zotero.Tags = new function() {
|
|||
sql = "DROP TABLE tagDelete";
|
||||
Zotero.DB.query(sql);
|
||||
Zotero.DB.commitTransaction();
|
||||
Zotero.Prefs.set('purge.tags', false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -393,6 +398,8 @@ Zotero.Tags = new function() {
|
|||
finally {
|
||||
Zotero.UnresponsiveScriptIndicator.enable();
|
||||
}
|
||||
|
||||
Zotero.Prefs.set('purge.tags', false);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -634,10 +634,18 @@ Zotero.Fulltext = new function(){
|
|||
|
||||
function clearItemWords(itemID){
|
||||
Zotero.DB.beginTransaction();
|
||||
Zotero.DB.query("DELETE FROM fulltextItems WHERE itemID=" + itemID);
|
||||
Zotero.DB.query("DELETE FROM fulltextItemWords WHERE itemID=" + itemID);
|
||||
var sql = "SELECT rowid FROM fulltextItems WHERE itemID=? LIMIT 1";
|
||||
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();
|
||||
|
||||
if (indexed) {
|
||||
Zotero.Prefs.set('purge.fulltext', true);
|
||||
}
|
||||
|
||||
// Delete fulltext cache file if there is one
|
||||
this.clearCacheFile(itemID);
|
||||
}
|
||||
|
@ -934,9 +942,15 @@ Zotero.Fulltext = new function(){
|
|||
|
||||
|
||||
function purgeUnusedWords() {
|
||||
if (!Zotero.Prefs.get('purge.fulltext')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var sql = "DELETE FROM fulltextWords WHERE wordID NOT IN "
|
||||
+ "(SELECT wordID FROM fulltextItemWords)";
|
||||
Zotero.DB.query(sql);
|
||||
|
||||
Zotero.Prefs.set('purge.fulltext', false)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -155,6 +155,9 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
|
|||
Zotero.ItemTreeView.prototype.refresh = function()
|
||||
{
|
||||
Zotero.debug('Refreshing items list');
|
||||
|
||||
var usiDisabled = Zotero.UnresponsiveScriptIndicator.disable();
|
||||
|
||||
this._searchMode = this._itemGroup.isSearchMode();
|
||||
|
||||
var oldRows = this.rowCount;
|
||||
|
@ -228,6 +231,10 @@ Zotero.ItemTreeView.prototype.refresh = function()
|
|||
if (diff != 0) {
|
||||
this._treebox.rowCountChanged(0, diff);
|
||||
}
|
||||
|
||||
if (usiDisabled) {
|
||||
Zotero.UnresponsiveScriptIndicator.enable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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() {
|
||||
Zotero.Tags.reloadAll();
|
||||
Zotero.Collections.reloadAll();
|
||||
|
@ -2103,7 +2119,9 @@ Zotero.UnresponsiveScriptIndicator = new function() {
|
|||
**/
|
||||
function disable() {
|
||||
// don't do anything if already disabled
|
||||
if(_isDisabled) return;
|
||||
if (_isDisabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
|
||||
getService(Components.interfaces.nsIPrefBranch);
|
||||
|
@ -2111,6 +2129,7 @@ Zotero.UnresponsiveScriptIndicator = new function() {
|
|||
prefService.setIntPref("dom.max_chrome_script_run_time", 0);
|
||||
|
||||
_isDisabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,3 +103,9 @@ pref("extensions.zotero.sync.storage.deleteDelayDays", 30);
|
|||
// Proxy
|
||||
pref("extensions.zotero.proxies.autoRecognize", 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);
|
Loading…
Reference in a new issue