diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 6a72d1812..54d6d422d 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -417,6 +417,15 @@ var ZoteroPane = new function() // Focus the quicksearch on pane open setTimeout("document.getElementById('zotero-tb-search').inputField.select();", 1); + // Auto-empty trashed items older than a certain number of days + var days = Zotero.Prefs.get('trashAutoEmptyDays'); + if (days) { + var d = new Date(); + var deleted = Zotero.Items.emptyTrash(days); + var d2 = new Date(); + Zotero.debug("Emptied old items from trash in " + (d2 - d) + " ms"); + } + var d = new Date(); Zotero.purgeDataObjects(); var d2 = new Date(); diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 8cf9a6922..0d806b254 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -130,8 +130,11 @@ Zotero.Items = new function() { * Zotero.Item objects * @return {Zotero.Item[]|Integer[]} */ - this.getDeleted = function (asIDs) { + this.getDeleted = function (asIDs, days) { var sql = "SELECT itemID FROM deletedItems"; + if (days) { + sql += " WHERE dateDeleted<=DATE('NOW', '-" + parseInt(days) + " DAYS')"; + } var ids = Zotero.DB.columnQuery(sql); if (asIDs) { return ids; @@ -397,14 +400,18 @@ Zotero.Items = new function() { } - this.emptyTrash = function () { + /** + * @param {Integer} days Only delete items deleted more than this many days ago + */ + this.emptyTrash = function (days) { Zotero.DB.beginTransaction(); - var deletedIDs = this.getDeleted(true); + var deletedIDs = this.getDeleted(true, days); if (deletedIDs) { this.erase(deletedIDs); + Zotero.Notifier.trigger('refresh', 'collection', 0); } - Zotero.Notifier.trigger('refresh', 'collection', 0); Zotero.DB.commitTransaction(); + return deletedIDs ? deletedIDs.length : 0; } diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 8ed4edf0e..9febe8f10 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -2906,6 +2906,11 @@ Zotero.Schema = new function(){ Zotero.DB.query("UPDATE savedSearchConditions SET condition='libraryCatalog' WHERE condition='repository'"); } + // 2.1 + if (i==74) { + Zotero.DB.query("CREATE INDEX deletedItems_dateDeleted ON deletedItems(dateDeleted)"); + } + Zotero.wait(); } diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 72e35783d..c8f2336f6 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -35,6 +35,7 @@ pref("extensions.zotero.launchNonNativeFiles", false); pref("extensions.zotero.sortNotesChronologically", false); pref("extensions.zotero.sortAttachmentsChronologically", false); pref("extensions.zotero.showTrashWhenEmpty", true); +pref("extensions.zotero.trashAutoEmptyDays", 30); pref("extensions.zotero.viewOnDoubleClick", true); pref("extensions.zotero.groups.copyChildLinks", true); diff --git a/userdata.sql b/userdata.sql index 661205e8b..1a99a45b1 100644 --- a/userdata.sql +++ b/userdata.sql @@ -1,4 +1,4 @@ --- 73 +-- 74 -- Copyright (c) 2009 Center for History and New Media -- George Mason University, Fairfax, Virginia, USA @@ -212,6 +212,7 @@ CREATE TABLE deletedItems ( itemID INTEGER PRIMARY KEY, dateDeleted DEFAULT CURRENT_TIMESTAMP NOT NULL ); +CREATE INDEX deletedItems_dateDeleted ON deletedItems(dateDeleted); CREATE TABLE relations ( libraryID INT NOT NULL,