[balsa] Message threading cleanup



commit 928e1f4668852a5ab86cf2f3855ae5d6c3574ed5
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Jan 31 13:43:36 2020 -0500

    Message threading cleanup
    
    Remove duplicate idle handler, and make
    libbalsa_mailbox_local_set_threading_info() private.
    
    * libbalsa/mailbox_local.c (libbalsa_mailbox_local_init),
      (libbalsa_mailbox_local_finalize),
      (libbalsa_mailbox_local_close_mailbox): drop thread_id, and use
        set_threading_id instead;
      (message_match_real): add test for msgno > 0;
      (lbm_local_set_threading_info): renamed from
      libbalsa_mailbox_local_set_threading_info now that it is private;
      (libbalsa_mailbox_local_set_threading): use the new name;
      (lbm_local_prepare_msgno): declare it void; no gboolean return
        value is needed;
      (libbalsa_mailbox_local_prepare_threading): drop the idle handler;
    * libbalsa/mailbox_local.h:
      libbalsa_mailbox_local_set_threading_info() is now private;
    * libbalsa/mailbox_mbox.c (parse_mailbox): do not call it.

 ChangeLog                | 24 ++++++++++++++
 libbalsa/mailbox_local.c | 86 +++++++++++-------------------------------------
 libbalsa/mailbox_local.h |  2 --
 libbalsa/mailbox_mbox.c  |  1 -
 4 files changed, 44 insertions(+), 69 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 28502f266..66312c02a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2020-01-31  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Message threading cleanup
+
+       Remove duplicate idle handler, and make
+       libbalsa_mailbox_local_set_threading_info() private.
+
+       * libbalsa/mailbox_local.c (libbalsa_mailbox_local_init),
+       (libbalsa_mailbox_local_finalize),
+       (libbalsa_mailbox_local_close_mailbox): drop thread_id, and use
+       set_threading_id instead;
+       (message_match_real): add test for msgno > 0;
+       (lbm_local_set_threading_info): renamed from
+       libbalsa_mailbox_local_set_threading_info now that it is
+       private;
+       (libbalsa_mailbox_local_set_threading): use the new name;
+       (lbm_local_prepare_msgno): declare it void; no gboolean return
+       value is needed;
+       (libbalsa_mailbox_local_prepare_threading): drop the idle
+       handler;
+       * libbalsa/mailbox_local.h:
+       libbalsa_mailbox_local_set_threading_info() is now private;
+       * libbalsa/mailbox_mbox.c (parse_mailbox): do not call it.
+
 2020-01-31  Peter Bloomfield  <pbloomfield bellsouth net>
 
        mailbox-local: Fetch threading info when needed
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 3ffa5579c..8f3290772 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -44,7 +44,6 @@ struct _LibBalsaMailboxLocalPrivate {
     guint sync_cnt; /* we do not want to rely on the time of last sync since
                      * some sync can be faster than others. Instead, we
                      * average the syncing time for mailbox. */
-    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 set_threading_id; /* id of the idle set-threading job */
@@ -192,7 +191,6 @@ libbalsa_mailbox_local_init(LibBalsaMailboxLocal * local)
     priv->sync_id   = 0;
     priv->sync_time = 0;
     priv->sync_cnt  = 0;
-    priv->thread_id = 0;
     priv->save_tree_id = 0;
 }
 
@@ -392,9 +390,6 @@ libbalsa_mailbox_local_finalize(GObject * object)
     if (priv->sync_id != 0)
         g_source_remove(priv->sync_id);
 
-    if (priv->thread_id != 0)
-        g_source_remove(priv->thread_id);
-
     if (priv->save_tree_id != 0)
         g_source_remove(priv->save_tree_id);
 
@@ -755,9 +750,9 @@ libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
     libbalsa_mailbox_set_view_filter(mailbox,
                                      libbalsa_mailbox_get_view_filter(mailbox, TRUE), TRUE);
 
-    if (priv->thread_id) {
-        g_source_remove(priv->thread_id);
-        priv->thread_id = 0;
+    if (priv->set_threading_id != 0) {
+        g_source_remove(priv->set_threading_id);
+        priv->set_threading_id = 0;
         /* Rethread immediately. */
         libbalsa_mailbox_set_threading(mailbox);
     }
@@ -832,7 +827,7 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
     LibBalsaMailboxIndexEntry *entry =
         libbalsa_mailbox_get_index_entry(mailbox, msgno);
     LibBalsaMailboxLocalInfo *info =
-        msgno <= priv->threading_info->len ?
+        msgno > 0 && msgno <= priv->threading_info->len ?
         g_ptr_array_index(priv->threading_info, msgno - 1) : NULL;
 
     /* We may be able to match the msgno from info cached in entry or
@@ -1135,8 +1130,8 @@ libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
 static void lbml_thread_messages(LibBalsaMailbox *mailbox, gboolean subject_gather);
 static void lbml_threading_flat(LibBalsaMailbox * mailbox);
 
-void 
-libbalsa_mailbox_local_set_threading_info(LibBalsaMailboxLocal * local)
+static void
+lbm_local_set_threading_info(LibBalsaMailboxLocal * local)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
@@ -1200,7 +1195,7 @@ libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
 
-    libbalsa_mailbox_local_set_threading_info(local);
+    lbm_local_set_threading_info(local);
 #if defined(DEBUG_LOADING_AND_THREADING)
     printf("before load_messages: time=%lu\n", (unsigned long) time(NULL));
 #endif
@@ -1319,48 +1314,24 @@ lbm_local_update_view_filter(LibBalsaMailbox * mailbox,
  * at LibBalsaMailbox.
  */
 
-/* Helper: returns TRUE if msgno was not already cached, which means we
- * have new data for sorting or threading. */
-static gboolean
+/* Helper */
+static void
 lbm_local_prepare_msgno(LibBalsaMailboxLocal * local, guint msgno)
 {
     LibBalsaMailboxLocalPrivate *priv =
         libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMessage *message;
 
-    if (msgno <= priv->threading_info->len
-        && g_ptr_array_index(priv->threading_info, msgno - 1))
-        return FALSE;
+    if (msgno > 0 && msgno <= priv->threading_info->len
+        && g_ptr_array_index(priv->threading_info, msgno - 1) != NULL)
+        return;
 
     message =
         libbalsa_mailbox_get_message((LibBalsaMailbox *) local, msgno);
-    if (!message)
-        return FALSE;
-
-    lbm_local_cache_message(local, msgno, message);
-    g_object_unref(message);
-
-    return TRUE;
-}
-
-/* Idle handler. */
-static gboolean
-lbm_local_thread_idle(LibBalsaMailboxLocal * local)
-{
-    LibBalsaMailboxLocalPrivate *priv =
-        libbalsa_mailbox_local_get_instance_private(local);
-    LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(local);
-
-    libbalsa_lock_mailbox(mailbox);
-
-    if (MAILBOX_OPEN(mailbox))
-        libbalsa_mailbox_set_threading(mailbox);
-    priv->thread_id = 0;
-
-    libbalsa_unlock_mailbox(mailbox);
-    g_object_unref(local);
-
-    return FALSE;
+    if (message != NULL) {
+        lbm_local_cache_message(local, msgno, message);
+        g_object_unref(message);
+    }
 }
 
 /* The class method; prepare messages from start + 1 to the end of the
@@ -1370,16 +1341,13 @@ libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
                                          guint start)
 {
     LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
-    LibBalsaMailboxLocalPrivate *priv =
-        libbalsa_mailbox_local_get_instance_private(local);
     guint msgno;
-    gboolean need_thread = FALSE;
     gchar *text;
     guint total;
     LibBalsaProgress progress = LIBBALSA_PROGRESS_INIT;
 
     libbalsa_lock_mailbox(mailbox);
-    libbalsa_mailbox_local_set_threading_info(local);
+    lbm_local_set_threading_info(local);
 
     text = g_strdup_printf(_("Preparing %s"), libbalsa_mailbox_get_name(mailbox));
     total = libbalsa_mailbox_total_messages(mailbox);
@@ -1387,27 +1355,13 @@ libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
     g_free(text);
 
     for (msgno = start + 1; msgno <= total; msgno++) {
-        if (lbm_local_prepare_msgno(local, msgno)) {
-            need_thread = TRUE;
-            libbalsa_progress_set_fraction(&progress,
-                                           ((gdouble) msgno) /
-                                           ((gdouble) (total - start)));
-        }
+        lbm_local_prepare_msgno(local, msgno);
+        libbalsa_progress_set_fraction(&progress,
+                                       ((gdouble) msgno) / ((gdouble) (total - start)));
     }
 
     libbalsa_progress_set_text(&progress, NULL, 0);
 
-    if (need_thread && !priv->thread_id) {
-        if (libbalsa_mailbox_get_threading_type(mailbox) !=
-            LB_MAILBOX_THREADING_FLAT
-            || libbalsa_mailbox_get_sort_field(mailbox) !=
-            LB_MAILBOX_SORT_NO) {
-            g_object_ref(local);
-            priv->thread_id =
-                g_idle_add((GSourceFunc) lbm_local_thread_idle, local);
-        }
-    }
-
     libbalsa_unlock_mailbox(mailbox);
 
     return TRUE;
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index a0aacbf5b..f995a24d3 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -67,8 +67,6 @@ LibBalsaMailbox *libbalsa_mailbox_local_new(const gchar * path,
                                             gboolean      create);
 gint libbalsa_mailbox_local_set_path(LibBalsaMailboxLocal * mailbox,
                                     const gchar * path, gboolean create);
-void libbalsa_mailbox_local_set_threading_info(LibBalsaMailboxLocal *
-                                               local);
 
 #define libbalsa_mailbox_local_get_path(local) \
        (libbalsa_mailbox_get_url((LibBalsaMailbox*)local)+7)
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index efdeb21a9..250c3deef 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -443,7 +443,6 @@ parse_mailbox(LibBalsaMailboxMbox * mbox)
                                    "^Status|^X-Status|^MIME-Version",
                                   lbm_mbox_header_cb, &msg_info_p);
 
-    libbalsa_mailbox_local_set_threading_info(local);
     msg_info.local_info.message = NULL;
     msg_info.local_info.loaded  = FALSE;
     while (!g_mime_parser_eos(gmime_parser)) {


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