[evolution-data-server] Provide CamelFolder::get_message_cached()



commit 9f3667eb8026277f0a2be1a3ef681849822354ef
Author: Milan Crha <mcrha redhat com>
Date:   Mon Sep 26 21:03:17 2011 +0200

    Provide CamelFolder::get_message_cached()
    
    This is used in camel_folder_get_message_sync(), as the first attempt
    to get a message without involving the folder lock, thus it's supposed
    to be quicker. The implementer may not do any network I/O while inside
    this function. Also, returning NULL is not considered as an error, it
    just means that the message is not downloaded in the local cache yet,
    thus the usual process of invoking folder's lock and calling actual
    implementation of get_message_sync() follows. Defining this function
    is not mandatory for descendants.

 camel/camel-folder.c |   37 +++++++++++++++++++++++++------------
 camel/camel-folder.h |    4 ++++
 2 files changed, 29 insertions(+), 12 deletions(-)
---
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index e1ae8d7..1f0d396 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -3259,7 +3259,7 @@ camel_folder_get_message_sync (CamelFolder *folder,
                                GError **error)
 {
 	CamelFolderClass *class;
-	CamelMimeMessage *message;
+	CamelMimeMessage *message = NULL;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
 	g_return_val_if_fail (message_uid != NULL, NULL);
@@ -3271,20 +3271,33 @@ camel_folder_get_message_sync (CamelFolder *folder,
 		cancellable, _("Retrieving message '%s' in %s"),
 		message_uid, camel_folder_get_display_name (folder));
 
-	camel_folder_lock (folder, CAMEL_FOLDER_REC_LOCK);
-
-	/* Check for cancellation after locking. */
-	if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
-		camel_folder_unlock (folder, CAMEL_FOLDER_REC_LOCK);
-		camel_operation_pop_message (cancellable);
-		return NULL;
+	if (class->get_message_cached) {
+		/* Return cached message, if available locally; this should not do any
+		   network I/O, only check if message is already downloaded and return
+		   it quicker, not being blocked by the folder's lock.
+		   Returning NULL is not considered as an error, it just means that
+		   the message is still to-be-downloaded.
+		*/
+		message = class->get_message_cached (
+			folder, message_uid, cancellable);
 	}
 
-	message = class->get_message_sync (
-		folder, message_uid, cancellable, error);
-	CAMEL_CHECK_GERROR (folder, get_message_sync, message != NULL, error);
+	if (!message) {
+		camel_folder_lock (folder, CAMEL_FOLDER_REC_LOCK);
 
-	camel_folder_unlock (folder, CAMEL_FOLDER_REC_LOCK);
+		/* Check for cancellation after locking. */
+		if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
+			camel_folder_unlock (folder, CAMEL_FOLDER_REC_LOCK);
+			camel_operation_pop_message (cancellable);
+			return NULL;
+		}
+
+		message = class->get_message_sync (
+			folder, message_uid, cancellable, error);
+		CAMEL_CHECK_GERROR (folder, get_message_sync, message != NULL, error);
+
+		camel_folder_unlock (folder, CAMEL_FOLDER_REC_LOCK);
+	}
 
 	if (message) {
 		CamelStore *store;
diff --git a/camel/camel-folder.h b/camel/camel-folder.h
index 896475e..3e49886 100644
--- a/camel/camel-folder.h
+++ b/camel/camel-folder.h
@@ -204,6 +204,10 @@ struct _CamelFolderClass {
 	gchar *		(*get_filename)		(CamelFolder *folder,
 						 const gchar *uid,
 						 GError **error);
+	CamelMimeMessage *
+			(*get_message_cached)	(CamelFolder *folder,
+						 const gchar *message_uid,
+						 GCancellable *cancellable);
 
 	/* Synchronous I/O Methods */
 	gboolean	(*append_message_sync)	(CamelFolder *folder,



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