[evolution-kolab] CamelKolabIMAPXStore: make SQLite DB updates optional on folder info query



commit e7f8617887338d8e61562c5a1da861b9f78e11b0
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Jul 24 16:29:58 2012 +0200

    CamelKolabIMAPXStore: make SQLite DB updates optional on folder info query
    
    * when querying CamelFolderInfo, it is not always desirable
      to instantly update the persistent DBs
    * the automatic updates can now be switched off via added
      API

 src/libekolab/camel-kolab-imapx-store.c |  159 +++++++++++++++++++++++--------
 src/libekolab/camel-kolab-imapx-store.h |   13 +++
 2 files changed, 131 insertions(+), 41 deletions(-)
---
diff --git a/src/libekolab/camel-kolab-imapx-store.c b/src/libekolab/camel-kolab-imapx-store.c
index decc7bf..5a4eb6b 100644
--- a/src/libekolab/camel-kolab-imapx-store.c
+++ b/src/libekolab/camel-kolab-imapx-store.c
@@ -436,6 +436,7 @@ imapx_store_set_foldertype (CamelKolabIMAPXStore *self,
 static CamelFolderInfo*
 imapx_store_folder_info_build_restricted (CamelKolabIMAPXStore *self,
                                           const CamelFolderInfo *fi,
+                                          gboolean do_updatedb,
                                           GCancellable *cancellable,
                                           GError **err)
 {
@@ -458,7 +459,7 @@ imapx_store_folder_info_build_restricted (CamelKolabIMAPXStore *self,
 
 	folder_type = imapx_store_get_foldertype (self,
 	                                          fi->full_name,
-	                                          TRUE,
+	                                          do_updatedb,
 	                                          cancellable,
 	                                          &tmp_err);
 	if (tmp_err != NULL) { /* FIXME Is err set if operation got cancelled? */
@@ -468,6 +469,7 @@ imapx_store_folder_info_build_restricted (CamelKolabIMAPXStore *self,
 
 	next_fi = imapx_store_folder_info_build_restricted (self,
 	                                                    fi->next,
+	                                                    do_updatedb,
 	                                                    cancellable,
 	                                                    &tmp_err);
 	if (tmp_err != NULL) {/* FIXME Is err set if operation got cancelled? */
@@ -477,6 +479,7 @@ imapx_store_folder_info_build_restricted (CamelKolabIMAPXStore *self,
 
 	chld_fi = imapx_store_folder_info_build_restricted (self,
 	                                                    fi->child,
+	                                                    do_updatedb,
 	                                                    cancellable,
 	                                                    &tmp_err);
 	if (tmp_err != NULL) {  /* FIXME Is err set if operation got cancelled? */
@@ -522,6 +525,71 @@ imapx_store_folder_info_build_restricted (CamelKolabIMAPXStore *self,
 	return next_fi;
 }
 
+static CamelFolderInfo*
+imapx_store_get_folder_info_sync (CamelKolabIMAPXStore *self,
+                                  const gchar *top,
+                                  CamelStoreGetFolderInfoFlags flags,
+                                  gboolean do_updatedb,
+                                  GCancellable *cancellable,
+                                  GError **err)
+{
+	CamelKolabIMAPXStorePrivate *priv = NULL;
+	CamelFolderInfo *fi = NULL;
+	CamelFolderInfo *k_fi = NULL;
+	GError *tmp_err = NULL;
+
+	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
+	/* top may be NULL */
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
+
+	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (self);
+
+	g_mutex_lock (&(priv->kolab_finfo_lock));
+
+	fi = parent_store_class->get_folder_info_sync (CAMEL_STORE (self),
+	                                               top,
+	                                               flags,
+	                                               cancellable,
+	                                               &tmp_err);
+	if (tmp_err != NULL)
+		goto exit;
+
+	if (fi != NULL) {
+		k_fi = imapx_store_folder_info_build_restricted (self,
+		                                                 fi,
+		                                                 do_updatedb,
+		                                                 cancellable,
+		                                                 &tmp_err);
+		camel_store_free_folder_info (CAMEL_STORE (self), fi);
+
+		if (tmp_err != NULL)
+			goto exit;
+	}
+
+	if (k_fi == NULL) {
+		/* No folder information - returning NULL would
+		 * mean we would have to set an error, but no
+		 * folder info (all folders hidden or no type
+		 * information available) is not technically an
+		 * error here. It can happen, depending on the folder
+		 * type we're supposed to care for. Hence, we're
+		 * returning an empty (but non-NULL) CamelFolderInfo
+		 * in the hopes that the caller will know what to
+		 * do about it (i.e., display nothing).
+		 */
+		k_fi = camel_folder_info_new ();
+	}
+
+ exit:
+	if (tmp_err != NULL)
+		g_propagate_error (err, tmp_err);
+
+	g_mutex_unlock (&(priv->kolab_finfo_lock));
+
+	return k_fi;
+}
+
 /*----------------------------------------------------------------------------*/
 /* class functions */
 
@@ -589,10 +657,7 @@ kolab_imapx_store_get_folder_info_sync (CamelStore *self,
                                         GError **err)
 {
 	CamelKolabIMAPXStore *myself = NULL;
-	CamelKolabIMAPXStorePrivate *priv = NULL;
-	CamelFolderInfo *fi = NULL;
 	CamelFolderInfo *k_fi = NULL;
-	GError *tmp_err = NULL;
 
 	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
 	/* top may be NULL */
@@ -600,48 +665,37 @@ kolab_imapx_store_get_folder_info_sync (CamelStore *self,
 	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
 
 	myself = CAMEL_KOLAB_IMAPX_STORE (self);
-	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (myself);
 
-	g_mutex_lock (&(priv->kolab_finfo_lock));
+	k_fi = imapx_store_get_folder_info_sync (myself,
+	                                         top,
+	                                         flags,
+	                                         TRUE, /* update SQLite DBs */
+	                                         cancellable,
+	                                         err);
 
-	fi = parent_store_class->get_folder_info_sync (self,
-	                                               top,
-	                                               flags,
-	                                               cancellable,
-	                                               &tmp_err);
-	if (tmp_err != NULL)
-		goto exit;
-
-	if (fi != NULL) {
-		k_fi = imapx_store_folder_info_build_restricted (myself,
-		                                                 fi,
-		                                                 cancellable,
-		                                                 &tmp_err);
-		camel_store_free_folder_info (self, fi);
-
-		if (tmp_err != NULL)
-			goto exit;
-	}
+	return k_fi;
+}
 
-	if (k_fi == NULL) {
-		/* No folder information - returning NULL would
-		 * mean we would have to set an error, but no
-		 * folder info (all folders hidden or no type
-		 * information available) is not technically an
-		 * error here. It can happen, depending on the folder
-		 * type we're supposed to care for. Hence, we're
-		 * returning an empty (but non-NULL) CamelFolderInfo
-		 * in the hopes that the caller will know what to
-		 * do about it (i.e., display nothing).
-		 */
-		k_fi = camel_folder_info_new ();
-	}
+static CamelFolderInfo*
+kolab_imapx_store_get_folder_info_online (CamelKolabIMAPXStore *self,
+                                          const gchar *top,
+                                          CamelStoreGetFolderInfoFlags flags,
+                                          GCancellable *cancellable,
+                                          GError **err)
+{
+	CamelFolderInfo *k_fi = NULL;
 
- exit:
-	if (tmp_err != NULL)
-		g_propagate_error (err, tmp_err);
+	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
+	/* top may be NULL */
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
 
-	g_mutex_unlock (&(priv->kolab_finfo_lock));
+	k_fi = imapx_store_get_folder_info_sync (self,
+	                                         top,
+	                                         flags,
+	                                         FALSE, /* do not update DBs */
+	                                         cancellable,
+	                                         err);
 
 	return k_fi;
 }
@@ -701,6 +755,7 @@ kolab_imapx_store_create_folder_sync (CamelStore *self,
 
 	k_fi = imapx_store_folder_info_build_restricted (myself,
 	                                                 fi,
+	                                                 TRUE,
 	                                                 cancellable,
 	                                                 &tmp_err);
 	camel_store_free_folder_info (self, fi);
@@ -1103,6 +1158,7 @@ camel_kolab_imapx_store_class_init (CamelKolabIMAPXStoreClass *klass)
 	klass->set_folder_creation_type = kolab_imapx_store_set_folder_creation_type;
 	klass->set_folder_context = kolab_imapx_store_set_folder_context;
 	klass->get_folder_type = kolab_imapx_store_get_folder_type;
+	klass->get_folder_info_online = kolab_imapx_store_get_folder_info_online;
 	klass->resect_folder_list = kolab_imapx_store_resect_folder_list;
 }
 
@@ -1160,6 +1216,27 @@ camel_kolab_imapx_store_get_folder_type (CamelKolabIMAPXStore *self,
 	return foldertype;
 }
 
+CamelFolderInfo*
+camel_kolab_imapx_store_get_folder_info_online (CamelKolabIMAPXStore *self,
+                                                const gchar *top,
+                                                CamelStoreGetFolderInfoFlags flags,
+                                                GCancellable *cancellable,
+                                                GError **err)
+{
+	CamelKolabIMAPXStoreClass *klass = NULL;
+	CamelFolderInfo *k_fi = NULL;
+
+	g_return_val_if_fail (CAMEL_IS_KOLAB_IMAPX_STORE (self), NULL);
+
+	klass = CAMEL_KOLAB_IMAPX_STORE_GET_CLASS (self);
+	k_fi = klass->get_folder_info_online (self,
+	                                      top,
+	                                      flags,
+	                                      cancellable,
+	                                      err);
+	return k_fi;
+}
+
 GList*
 camel_kolab_imapx_store_resect_folder_list (CamelKolabIMAPXStore *self)
 {
diff --git a/src/libekolab/camel-kolab-imapx-store.h b/src/libekolab/camel-kolab-imapx-store.h
index 8fbf019..0c1dfc4 100644
--- a/src/libekolab/camel-kolab-imapx-store.h
+++ b/src/libekolab/camel-kolab-imapx-store.h
@@ -86,6 +86,12 @@ struct _CamelKolabIMAPXStoreClass {
 	                                      GCancellable *cancellable,
 	                                      GError **err);
 
+	CamelFolderInfo* (*get_folder_info_online) (CamelKolabIMAPXStore *self,
+	                                            const gchar *top,
+	                                            CamelStoreGetFolderInfoFlags flags,
+	                                            GCancellable *cancellable,
+	                                            GError **err);
+
 	GList* (*resect_folder_list) (CamelKolabIMAPXStore *self);
 };
 
@@ -110,6 +116,13 @@ camel_kolab_imapx_store_get_folder_type (CamelKolabIMAPXStore *self,
                                          GError **err);
 
 /* Kolab extension */
+CamelFolderInfo*
+camel_kolab_imapx_store_get_folder_info_online (CamelKolabIMAPXStore *self,
+                                                const gchar *top,
+                                                CamelStoreGetFolderInfoFlags flags,
+                                                GCancellable *cancellable,
+                                                GError **err);
+/* Kolab extension */
 GList*
 camel_kolab_imapx_store_resect_folder_list (CamelKolabIMAPXStore *self);
 



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