Update automatic trash emptying after 3872e646ac
And restore 'limit' parameter used for auto-empty
This commit is contained in:
parent
e25af42ef3
commit
fb61819f6b
|
@ -872,11 +872,13 @@ Zotero.Items = function() {
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {Function} [options.onProgress] - fn(progress, progressMax)
|
* @param {Function} [options.onProgress] - fn(progress, progressMax)
|
||||||
* @param {Integer} [options.days] - Only delete items deleted more than this many days ago
|
* @param {Integer} [options.days] - Only delete items deleted more than this many days ago
|
||||||
|
* @param {Integer} [options.limit] - Number of items to delete
|
||||||
*/
|
*/
|
||||||
this.emptyTrash = async function (libraryID, options = {}) {
|
this.emptyTrash = async function (libraryID, options = {}) {
|
||||||
if (typeof arguments[1] == 'number') {
|
if (arguments.length > 2 || typeof arguments[1] == 'number') {
|
||||||
Zotero.warn("Zotero.Items.emptyTrash() has changed -- update your code");
|
Zotero.warn("Zotero.Items.emptyTrash() has changed -- update your code");
|
||||||
options.days = arguments[1];
|
options.days = arguments[1];
|
||||||
|
options.limit = arguments[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!libraryID) {
|
if (!libraryID) {
|
||||||
|
@ -886,6 +888,11 @@ Zotero.Items = function() {
|
||||||
var t = new Date();
|
var t = new Date();
|
||||||
|
|
||||||
var deleted = await this.getDeleted(libraryID, false, options.days);
|
var deleted = await this.getDeleted(libraryID, false, options.days);
|
||||||
|
|
||||||
|
if (options.limit) {
|
||||||
|
deleted = deleted.slice(0, options.limit);
|
||||||
|
}
|
||||||
|
|
||||||
var processed = 0;
|
var processed = 0;
|
||||||
if (deleted.length) {
|
if (deleted.length) {
|
||||||
let toDelete = {
|
let toDelete = {
|
||||||
|
@ -925,7 +932,7 @@ Zotero.Items = function() {
|
||||||
* Start idle observer to delete trashed items older than a certain number of days
|
* Start idle observer to delete trashed items older than a certain number of days
|
||||||
*/
|
*/
|
||||||
this._emptyTrashIdleObserver = null;
|
this._emptyTrashIdleObserver = null;
|
||||||
this._emptyTrashTimer = null;
|
this._emptyTrashTimeoutID = null;
|
||||||
this.startEmptyTrashTimer = function () {
|
this.startEmptyTrashTimer = function () {
|
||||||
this._emptyTrashIdleObserver = {
|
this._emptyTrashIdleObserver = {
|
||||||
observe: (subject, topic, data) => {
|
observe: (subject, topic, data) => {
|
||||||
|
@ -941,30 +948,31 @@ Zotero.Items = function() {
|
||||||
//
|
//
|
||||||
// TODO: increase number after dealing with slow
|
// TODO: increase number after dealing with slow
|
||||||
// tag.getLinkedItems() call during deletes
|
// tag.getLinkedItems() call during deletes
|
||||||
var num = 10;
|
let num = 50;
|
||||||
this.emptyTrash(Zotero.Libraries.userLibraryID, days, num)
|
this.emptyTrash(
|
||||||
.then(deleted => {
|
Zotero.Libraries.userLibraryID,
|
||||||
|
{
|
||||||
|
days,
|
||||||
|
limit: num
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then((deleted) => {
|
||||||
if (!deleted) {
|
if (!deleted) {
|
||||||
this._emptyTrashTimer = null;
|
this._emptyTrashTimeoutID = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a timer to do more every few seconds
|
// Set a timer to do more every few seconds
|
||||||
if (!this._emptyTrashTimer) {
|
this._emptyTrashTimeoutID = setTimeout(() => {
|
||||||
this._emptyTrashTimer = Components.classes["@mozilla.org/timer;1"]
|
this._emptyTrashIdleObserver.observe(null, 'timer-callback', null);
|
||||||
.createInstance(Components.interfaces.nsITimer);
|
}, 2500);
|
||||||
}
|
|
||||||
this._emptyTrashTimer.init(
|
|
||||||
this._emptyTrashIdleObserver.observe,
|
|
||||||
5 * 1000,
|
|
||||||
Components.interfaces.nsITimer.TYPE_ONE_SHOT
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// When no longer idle, cancel timer
|
// When no longer idle, cancel timer
|
||||||
else if (topic == 'back') {
|
else if (topic == 'back') {
|
||||||
if (this._emptyTrashTimer) {
|
if (this._emptyTrashTimeoutID) {
|
||||||
this._emptyTrashTimer.cancel();
|
clearTimeout(this._emptyTrashTimeoutID);
|
||||||
|
this._emptyTrashTimeoutID = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user