[geary: 51/66] Improve Geary.ImapDB.Database.run_gc method interface



commit 6464393c32475c72c64399246e3656d8a3332858
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date:   Thu May 7 15:58:29 2020 +1000

    Improve Geary.ImapDB.Database.run_gc method interface

 src/engine/imap-db/imap-db-database.vala           | 56 ++++++++++++++--------
 .../imap-engine-account-synchronizer.vala          | 15 +++---
 .../imap-engine/imap-engine-generic-account.vala   |  2 +-
 .../imap-engine/imap-engine-minimal-folder.vala    |  3 +-
 4 files changed, 48 insertions(+), 28 deletions(-)
---
diff --git a/src/engine/imap-db/imap-db-database.vala b/src/engine/imap-db/imap-db-database.vala
index f3dfc6b91..c119b9b68 100644
--- a/src/engine/imap-db/imap-db-database.vala
+++ b/src/engine/imap-db/imap-db-database.vala
@@ -18,6 +18,26 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
     /** SQLite UTF-8 collation name. */
     public const string UTF8_COLLATE = "UTF8COLL";
 
+    /** Options to use when running garbage collection. */
+    [Flags]
+    public enum GarbageCollectionOptions {
+
+        /** Reaping will not be forced and vacuuming not permitted. */
+        NONE,
+
+        /**
+         * Reaping will be performed, regardless of recommendation.
+         */
+        FORCE_REAP,
+
+        /**
+         * Whether to permit database vacuum.
+         *
+         * Vacuuming is performed in the foreground.
+         */
+        ALLOW_VACUUM;
+    }
+
     public bool want_background_vacuum { get; set; default = false; }
 
 
@@ -57,6 +77,9 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
     private GC? gc = null;
     private Cancellable gc_cancellable = new Cancellable();
 
+
+
+
     public Database(GLib.File db_file,
                     GLib.File schema_dir,
                     GLib.File attachments_path,
@@ -75,7 +98,8 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
         throws Error {
         yield base.open(flags, cancellable);
 
-        yield run_gc(cancellable);
+        Geary.ClientService services_to_pause[] = {};
+        yield run_gc(NONE, services_to_pause, cancellable);
     }
 
     /**
@@ -83,16 +107,10 @@ 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 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.
      */
-    public async void run_gc(GLib.Cancellable? cancellable,
-                             bool force_reap = false,
-                             bool allow_vacuum = false,
-                             Geary.Imap.ClientService? imap_service = null,
-                             Geary.Smtp.ClientService? smtp_service = null)
+    public async void run_gc(GarbageCollectionOptions options,
+                             Geary.ClientService[] services_to_pause,
+                             GLib.Cancellable? cancellable)
                                  throws Error {
 
         if (this.gc != null) {
@@ -116,12 +134,11 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
         // VACUUM needs to execute in the foreground with the user given a busy prompt (and cannot
         // be run at the same time as REAP)
         if ((recommended & GC.RecommendedOperation.VACUUM) != 0) {
-            if (allow_vacuum) {
+            if (GarbageCollectionOptions.ALLOW_VACUUM in options) {
                 this.want_background_vacuum = false;
-                if (imap_service != null)
-                    yield imap_service.stop(gc_cancellable);
-                if (smtp_service != null)
-                    yield smtp_service.stop(gc_cancellable);
+                foreach (ClientService service in services_to_pause) {
+                    yield service.stop(gc_cancellable);
+                }
 
                 if (!vacuum_monitor.is_in_progress)
                     vacuum_monitor.notify_start();
@@ -138,10 +155,9 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
                         vacuum_monitor.notify_finish();
                 }
 
-                if (imap_service != null)
-                    yield imap_service.start(gc_cancellable);
-                if (smtp_service != null)
-                    yield smtp_service.start(gc_cancellable);
+                foreach (ClientService service in services_to_pause) {
+                    yield service.start(gc_cancellable);
+                }
             } else {
                 // Flag a vacuum to run later when we've been idle in the background
                 debug("Flagging desire to GC vacuum");
@@ -156,7 +172,7 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
         }
 
         // REAP can run in the background while the application is executing
-        if (force_reap || (recommended & GC.RecommendedOperation.REAP) != 0) {
+        if (GarbageCollectionOptions.FORCE_REAP in options || (recommended & GC.RecommendedOperation.REAP) 
!= 0) {
             // run in the background and allow application to continue running
             this.gc.reap_async.begin(gc_cancellable, on_reap_async_completed);
         } else {
diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala 
b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
index 8ddd353fc..86a729673 100644
--- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala
+++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
@@ -109,11 +109,13 @@ private class Geary.ImapEngine.AccountSynchronizer :
 
                 // 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,
-                                              messages_detached,
-                                              true,
-                                              account.imap,
-                                              account.smtp);
+                Geary.ImapDB.Database.GarbageCollectionOptions options = ALLOW_VACUUM;
+                if (messages_detached) {
+                    options |= FORCE_REAP;
+                }
+                account.local.db.run_gc.begin(options,
+                                              {account.imap, account.smtp},
+                                              cancellable);
             });
         }
     }
@@ -448,7 +450,8 @@ private class Geary.ImapEngine.GarbageCollectPostMessageDetach: AccountOperation
 
         // Run basic GC
         GenericAccount generic_account = (GenericAccount) account;
-        yield generic_account.local.db.run_gc(cancellable);
+        Geary.ClientService services_to_pause[] = {};
+        yield generic_account.local.db.run_gc(NONE, services_to_pause, cancellable);
     }
 
     public override bool equal_to(AccountOperation op) {
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 1c3097b0d..a192ca47e 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -583,7 +583,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
             this.old_messages_background_cleanup_request(cancellable);
         } else if (local.db.want_background_vacuum) {
             // Vacuum has been flagged as needed, run it
-            local.db.run_gc.begin(cancellable, false, true, this.imap, this.smtp);
+            local.db.run_gc.begin(ALLOW_VACUUM, {this.imap, this.smtp}, cancellable);
         }
     }
 
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index cc510b1f3..20fdc2c2b 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -1299,7 +1299,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // expunge from the remote
         yield this.replay_queue.checkpoint(cancellable);
 
-        yield this._account.local.db.run_gc(cancellable);
+        Geary.ClientService services_to_pause[] = {};
+        yield this._account.local.db.run_gc(NONE, services_to_pause, cancellable);
     }
 
     private void check_open(string method) throws EngineError {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]