[geary: 11/66] Old message cleanup after folder becomes available



commit 1e8465f5559181f7fdd0208cdc48c5b49fb36093
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date:   Wed Jan 8 12:58:54 2020 +0100

    Old message cleanup after folder becomes available
    
    Simple mechanism for triggering GC reap after messages were removed
    during folder check on becoming available

 src/engine/imap-db/imap-db-database.vala           | 22 ++++++++++++++++++++++
 .../imap-engine-account-synchronizer.vala          | 12 ++++++++++++
 2 files changed, 34 insertions(+)
---
diff --git a/src/engine/imap-db/imap-db-database.vala b/src/engine/imap-db/imap-db-database.vala
index 1eaad6e95..f91d0bea0 100644
--- a/src/engine/imap-db/imap-db-database.vala
+++ b/src/engine/imap-db/imap-db-database.vala
@@ -50,6 +50,8 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
 
     private const int OPEN_PUMP_EVENT_LOOP_MSEC = 100;
 
+    private const uint DELAY_GC_AFTER_OLD_MESSAGE_CLEANUP_SECONDS = 30;
+
     private ProgressMonitor upgrade_monitor;
     private ProgressMonitor vacuum_monitor;
     private bool new_db = false;
@@ -57,6 +59,10 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
     private GC? gc = null;
     private Cancellable gc_cancellable = new Cancellable();
 
+    private TimeoutManager gc_post_old_message_detach_timer;
+    // Cancellable from account synchronizer for GC after old message cleanup
+    private Cancellable? post_gc_cleanup_cancellable;
+
     public Database(GLib.File db_file,
                     GLib.File schema_dir,
                     GLib.File attachments_path,
@@ -66,6 +72,11 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
         this.attachments_path = attachments_path;
         this.upgrade_monitor = upgrade_monitor;
         this.vacuum_monitor = vacuum_monitor;
+
+        this.gc_post_old_message_detach_timer =
+            new TimeoutManager.seconds(
+                DELAY_GC_AFTER_OLD_MESSAGE_CLEANUP_SECONDS, run_gc_post_old_message_detach
+            );
     }
 
     /**
@@ -179,6 +190,17 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
         base.close(cancellable);
     }
 
+    public void schedule_gc_after_old_messages_cleanup(Cancellable? cancellable) {
+        this.post_gc_cleanup_cancellable = cancellable;
+        this.gc_post_old_message_detach_timer.start();
+    }
+
+    public void run_gc_post_old_message_detach() {
+        debug("Requesting GC post old message cleanup");
+        run_gc.begin(this.post_gc_cleanup_cancellable);
+        this.post_gc_cleanup_cancellable = null;
+    }
+
     protected override void starting_upgrade(int current_version, bool new_db) {
         this.new_db = new_db;
 
diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala 
b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
index 654ca0397..e5e64d840 100644
--- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala
+++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
@@ -71,6 +71,9 @@ private class Geary.ImapEngine.AccountSynchronizer :
                     )
                     : new RefreshFolderSync(this.account, imap_folder);
 
+                if (became_available)
+                    ((CheckFolderSync) 
op).old_message_detached.connect(this.old_messages_removed_during_sync);
+
                 try {
                     this.account.queue_operation(op);
                 } catch (Error err) {
@@ -89,6 +92,13 @@ private class Geary.ImapEngine.AccountSynchronizer :
         }
     }
 
+    private void old_messages_removed_during_sync(Cancellable cancellable) {
+        // This is not a daily cleanup. We've detached some messages, let's GC if
+        // recommended.
+        GenericAccount account = (GenericAccount) this.account;
+        account.local.db.schedule_gc_after_old_messages_cleanup(cancellable);
+    }
+
     private void on_account_prefetch_changed() {
         this.prefetch_timer.start();
     }
@@ -219,6 +229,7 @@ private class Geary.ImapEngine.RefreshFolderSync : FolderOperation {
  */
 private class Geary.ImapEngine.CheckFolderSync : RefreshFolderSync {
 
+    public signal void old_message_detached(Cancellable cancellable);
 
     private DateTime sync_max_epoch;
 
@@ -250,6 +261,7 @@ private class Geary.ImapEngine.CheckFolderSync : RefreshFolderSync {
             Gee.Collection<Geary.EmailIdentifier>? detached_ids = yield 
local_folder.detach_emails_before_timestamp(prefetch_max_epoch, cancellable);
             if (detached_ids != null) {
                 this.folder.email_locally_removed(detached_ids);
+                old_message_detached(cancellable);
             }
         }
 


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