[balsa/gtk3] Improve caching of local mailbox message tree



commit 9eccdb05f8a98c39d01c1f1ebf827bd5d267b190
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Mar 2 16:51:03 2013 -0500

    Improve caching of local mailbox message tree
    
        * libbalsa/mailbox.c (lbm_changed_schedule_idle),
        (libbalsa_mailbox_msgno_filt_in),
        (libbalsa_mailbox_msgno_filt_out): set mailbox_changed only when
        it really has changed.
        * libbalsa/mailbox_local.c (libbalsa_mailbox_local_class_init),
        (libbalsa_mailbox_local_changed), (lbm_local_save_tree_real),
        (lbm_local_queue_save_tree), (lbml_load_messages_idle_cb),
        (libbalsa_mailbox_local_load_messages): implement the "changed"
        vfunc, and use it to schedule saving the message tree structure.
        * libbalsa/mailbox_local.h: new member to temporarily hold the
        current last msgno.

 ChangeLog                |   14 ++++++++++++++
 libbalsa/mailbox.c       |    3 ++-
 libbalsa/mailbox_local.c |   43 +++++++++++++++++++++----------------------
 libbalsa/mailbox_local.h |    1 +
 4 files changed, 38 insertions(+), 23 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ab9b66b..6ef801a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2013-03-02  Peter Bloomfield
 
+       * libbalsa/mailbox.c (lbm_changed_schedule_idle),
+       (libbalsa_mailbox_msgno_filt_in),
+       (libbalsa_mailbox_msgno_filt_out): set mailbox_changed only when
+       it really has changed.
+       * libbalsa/mailbox_local.c (libbalsa_mailbox_local_class_init),
+       (libbalsa_mailbox_local_changed), (lbm_local_save_tree_real),
+       (lbm_local_queue_save_tree), (lbml_load_messages_idle_cb),
+       (libbalsa_mailbox_local_load_messages): implement the "changed"
+       vfunc, and use it to schedule saving the message tree structure.
+       * libbalsa/mailbox_local.h: new member to temporarily hold the
+       current last msgno.
+
+2013-03-02  Peter Bloomfield
+
        * libbalsa/server.c (libbalsa_server_save_config): report
        error saving password.
 
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 1ce89f3..980e3cb 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -743,7 +743,6 @@ lbm_changed_idle_cb(LibBalsaMailbox * mailbox)
 static void
 lbm_changed_schedule_idle(LibBalsaMailbox * mailbox)
 {
-    mailbox->msg_tree_changed = TRUE;
     if (!mailbox->changed_idle_id)
         mailbox->changed_idle_id =
             g_idle_add((GSourceFunc) lbm_changed_idle_cb, mailbox);
@@ -1411,6 +1410,7 @@ libbalsa_mailbox_msgno_filt_in(LibBalsaMailbox *mailbox, guint seqno)
                   path, &iter);
     gtk_tree_path_free(path);
 
+    mailbox->msg_tree_changed = TRUE;
     lbm_changed_schedule_idle(mailbox);
 
     gdk_threads_leave();
@@ -1579,6 +1579,7 @@ libbalsa_mailbox_msgno_filt_out(LibBalsaMailbox * mailbox, GNode * node)
     gtk_tree_path_free(path);
     mailbox->stamp++;
 
+    mailbox->msg_tree_changed = TRUE;
     lbm_changed_schedule_idle(mailbox);
 
     gdk_threads_leave();
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 30ea057..b9c47cd 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -45,6 +45,7 @@ static void libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass *klass);
 static void libbalsa_mailbox_local_init(LibBalsaMailboxLocal * mailbox);
 static void libbalsa_mailbox_local_finalize(GObject * object);
 
+static void libbalsa_mailbox_local_changed(LibBalsaMailbox * mailbox);
 static void libbalsa_mailbox_local_save_config(LibBalsaMailbox * mailbox,
                                               const gchar * prefix);
 static void libbalsa_mailbox_local_load_config(LibBalsaMailbox * mailbox,
@@ -142,6 +143,8 @@ libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
 
     object_class->finalize = libbalsa_mailbox_local_finalize;
 
+    libbalsa_mailbox_class->changed =
+       libbalsa_mailbox_local_changed;
     libbalsa_mailbox_class->save_config =
        libbalsa_mailbox_local_save_config;
     libbalsa_mailbox_class->load_config =
@@ -403,6 +406,14 @@ libbalsa_mailbox_local_finalize(GObject * object)
        G_OBJECT_CLASS(parent_class)->finalize(object);
 }
 
+static void lbm_local_queue_save_tree(LibBalsaMailboxLocal * local);
+
+static void
+libbalsa_mailbox_local_changed(LibBalsaMailbox * mailbox)
+{
+    lbm_local_queue_save_tree(LIBBALSA_MAILBOX_LOCAL(mailbox));
+}
+
 static void
 libbalsa_mailbox_local_save_config(LibBalsaMailbox * mailbox,
                                   const gchar * prefix)
@@ -684,7 +695,6 @@ lbm_local_save_tree_real(LibBalsaMailboxLocal * local)
     if (MAILBOX_OPEN(mailbox) && mailbox->msg_tree_changed)
         lbm_local_save_tree(local);
     local->save_tree_id = 0;
-    g_object_unref(local);
 
     libbalsa_unlock_mailbox(mailbox);
 }
@@ -710,8 +720,7 @@ lbm_local_queue_save_tree(LibBalsaMailboxLocal * local)
 {
     if (!local->save_tree_id)
         local->save_tree_id =
-            g_idle_add((GSourceFunc) lbm_local_save_tree_idle,
-                       g_object_ref(local));
+            g_idle_add((GSourceFunc) lbm_local_save_tree_idle, local);
 }
 
 /* 
@@ -1015,16 +1024,10 @@ libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
         info->sender = g_strdup("");
 }
 
-typedef struct {
-    LibBalsaMailbox *mailbox;
-    guint msgno;
-} LbmlLoadMessagesInfo;
-
 static gboolean
-lbml_load_messages_idle_cb(LbmlLoadMessagesInfo * info)
+lbml_load_messages_idle_cb(LibBalsaMailbox * mailbox)
 {
-    LibBalsaMailbox *mailbox = info->mailbox;
-    guint msgno              = info->msgno;
+    guint msgno;
     guint new_messages;
     LibBalsaMailboxLocal *local;
     guint lastno;
@@ -1042,6 +1045,7 @@ lbml_load_messages_idle_cb(LbmlLoadMessagesInfo * info)
 
     local = (LibBalsaMailboxLocal *) mailbox;
     lastno = libbalsa_mailbox_total_messages(mailbox);
+    msgno = local->msgno;
     new_messages = lastno - msgno;
     lastn = g_node_last_child(mailbox->msg_tree);
     get_info = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info;
@@ -1072,21 +1076,16 @@ void
 libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
                                      guint msgno)
 {
-    LbmlLoadMessagesInfo *info;
     LibBalsaMailboxLocal *local;
 
     g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(mailbox));
-    local = (LibBalsaMailboxLocal *) mailbox;
-    if (local->load_messages_id)
-        return;
 
-    info = g_new(LbmlLoadMessagesInfo, 1);
-    info->mailbox = mailbox;
-    info->msgno   = msgno;
-    local->load_messages_id =
-        g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
-                        (GSourceFunc) lbml_load_messages_idle_cb, info,
-                        g_free);
+    local = (LibBalsaMailboxLocal *) mailbox;
+    if (!local->load_messages_id) {
+        local->msgno = msgno;
+        local->load_messages_id =
+            g_idle_add((GSourceFunc) lbml_load_messages_idle_cb, mailbox);
+    }
 }
 
 /*
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index 591fb51..e8d881d 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -71,6 +71,7 @@ struct _LibBalsaMailboxLocal {
     guint thread_id;    /* id of the idle mailbox thread job */
     guint save_tree_id; /* id of the idle mailbox save-tree job */
     guint load_messages_id; /* id of the idle load-messages job */
+    guint msgno;            /* where to start loading messages */
     GPtrArray *threading_info;
     LibBalsaMailboxLocalPool message_pool[LBML_POOL_SIZE];
     guint pool_seqno;


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