Commit ae193989 authored by Chris Heywood's avatar Chris Heywood

Improve cancel-ability of account storage cleanup

parent 075eb636
Pipeline #142719 failed with stages
in 18 minutes and 53 seconds
......@@ -98,6 +98,8 @@ internal class Application.Controller : Geary.BaseObject {
// Track whether storage cleanup is running
private bool storage_cleanup_running = false;
private GLib.Cancellable? storage_cleanup_cancellable;
/**
* Emitted when an account is added or is enabled.
......@@ -1408,6 +1410,21 @@ internal class Application.Controller : Geary.BaseObject {
*/
public void window_focus_in() {
this.all_windows_backgrounded_timeout.reset();
if (this.storage_cleanup_cancellable != null) {
this.storage_cleanup_cancellable.cancel();
// Cleanup was still running and we don't know where we got to so
// we'll clear each of these so it runs next time we're in the
// background
foreach (AccountContext context in this.accounts.values) {
context.cancellable.cancelled.disconnect(this.storage_cleanup_cancellable.cancel);
Geary.Account account = context.account;
account.last_storage_cleanup = null;
}
this.storage_cleanup_cancellable = null;
}
}
/**
......@@ -1795,9 +1812,15 @@ internal class Application.Controller : Geary.BaseObject {
private async void do_background_storage_cleanup() {
debug("Checking for backgrounded idle work");
storage_cleanup_running = true;
this.storage_cleanup_cancellable = new GLib.Cancellable();
foreach (AccountContext context in this.accounts.values) {
Geary.Account account = context.account;
yield account.cleanup_storage(context.cancellable);
context.cancellable.cancelled.connect(this.storage_cleanup_cancellable.cancel);
yield account.cleanup_storage(this.storage_cleanup_cancellable);
if (this.storage_cleanup_cancellable.is_cancelled())
break;
context.cancellable.cancelled.disconnect(this.storage_cleanup_cancellable.cancel);
}
storage_cleanup_running = false;
}
......
......@@ -84,7 +84,7 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
* Reap should only be forced when there is known cleanup to perform and
* the interval based recommendation should be bypassed.
*
* TODO Passing of account is a WIP hack. It is currently used to both
* TODO Passing of the services is a WIP hack. It is currently used to both
* signify that it's an appropriate time to run a vacuum (ie. we're
* idle in the background) and provide access for stopping IMAP.
*/
......@@ -149,6 +149,12 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
}
}
// Abandon REAP if cancelled
if (cancellable != null && cancellable.is_cancelled()) {
cancellable.cancelled.disconnect(cancel_gc);
return;
}
// REAP can run in the background while the application is executing
if (force_reap || (recommended & GC.RecommendedOperation.REAP) != 0) {
// run in the background and allow application to continue running
......
......@@ -103,12 +103,15 @@ private class Geary.ImapEngine.AccountSynchronizer :
}
}
private void old_messages_background_cleanup(GLib.Cancellable? cancellable) {
private void old_messages_background_cleanup(GLib.Cancellable cancellable) {
if (this.account.is_open()) {
SyncDetachMonitor monitor = new SyncDetachMonitor();
send_all(this.account.list_folders(), false, true, monitor);
monitor.initialised = true;
monitor.completed.connect((messages_detached) => {
if (cancellable.is_cancelled())
return;
// Run GC. Reap is forced if messages were detached. Vacuum
// is allowed as we're running in the background.
account.local.db.run_gc.begin(cancellable,
......@@ -445,6 +448,9 @@ private class Geary.ImapEngine.GarbageCollectPostMessageDetach: AccountOperation
public override async void execute(GLib.Cancellable cancellable)
throws Error {
if (cancellable.is_cancelled())
return;
// Run basic GC
GenericAccount generic_account = (GenericAccount) account;
yield generic_account.local.db.run_gc(cancellable);
......
......@@ -17,8 +17,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
// we don't need to double check.
private const int REFRESH_FOLDER_LIST_SEC = 15 * 60;
// Frequency of account cleanup work, performed when idle with the app
// backgrounded
/** Minimum interval between account storage cleanup work */
private const uint APP_BACKGROUNDED_CLEANUP_WORK_INTERVAL_MINUTES = 60 * 24;
private const Geary.SpecialFolderType[] SUPPORTED_SPECIAL_FOLDERS = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment