[geary: 38/66] Improve cancel-ability of account storage cleanup
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary: 38/66] Improve cancel-ability of account storage cleanup
- Date: Tue, 30 Jun 2020 07:10:50 +0000 (UTC)
commit ae19398944b3401fe4992f042112990aeae3e36b
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date: Fri Jan 10 17:41:06 2020 +0100
Improve cancel-ability of account storage cleanup
src/client/application/application-controller.vala | 25 +++++++++++++++++++++-
src/engine/imap-db/imap-db-database.vala | 8 ++++++-
.../imap-engine-account-synchronizer.vala | 8 ++++++-
.../imap-engine/imap-engine-generic-account.vala | 3 +--
4 files changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/src/client/application/application-controller.vala
b/src/client/application/application-controller.vala
index 53d12ee96..9c07cf5b1 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -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;
}
diff --git a/src/engine/imap-db/imap-db-database.vala b/src/engine/imap-db/imap-db-database.vala
index 6dd97dcbd..36a32b54a 100644
--- a/src/engine/imap-db/imap-db-database.vala
+++ b/src/engine/imap-db/imap-db-database.vala
@@ -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
diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala
b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
index 1614531dc..cd27a6708 100644
--- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala
+++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
@@ -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);
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 3aaac788c..75adcb10b 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -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 = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]