Patch: use internal folder summary cache always



	Hi,

	This patch enables using the internal uid hashmap in camel folder
summary always. This should speed up things avoiding to do a n² process
to fetch new mails in folders.

	This patch also includes some changes to make save_append operation
work a bit better. Unfortunately, this is not enough as I'm getting
heavy corruption (mainly with move to operation in pop folders). Then,
it still needs more work, and that's why append is disabled now.

-- 
Jose Dapena Paz <jdapena igalia com>
Igalia
Index: libtinymail-camel/camel-lite/camel/camel-folder-summary.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-folder-summary.c	(revision 3168)
+++ libtinymail-camel/camel-lite/camel/camel-folder-summary.c	(working copy)
@@ -171,29 +171,23 @@
 find_message_info_with_uid (CamelFolderSummary *s, const char *uid)
 {
 	CamelMessageInfo *retval = NULL;
-	guint i = 0;
+	gboolean prepare_again = TRUE;
 
 	if (uid == NULL || strlen (uid) <= 0)
 		return NULL;
 
-	g_mutex_lock (s->hash_lock);
-	if (s->uidhash != NULL)
-		retval = g_hash_table_lookup (s->uidhash, uid);
-	g_mutex_unlock (s->hash_lock);
-
-	if (retval == NULL)
-		for (i=0; G_LIKELY (i < s->messages->len) ; i++)
-		{
-			CamelMessageInfo *info = s->messages->pdata[i];
-
-			/* This can cause cache trashing */
-			if (G_UNLIKELY (info->uid[0] == uid[0]) &&
-			    G_UNLIKELY (!strcmp (info->uid, uid)))
-			{
-				retval = info;
-				break;
-			}
+	do {
+		camel_folder_summary_prepare_hash (s);
+		
+		g_mutex_lock (s->hash_lock);
+		if (s->uidhash != NULL) {
+			retval = g_hash_table_lookup (s->uidhash, uid);
+			prepare_again = FALSE;
+		} else {
+			prepare_again = TRUE;
 		}
+		g_mutex_unlock (s->hash_lock);
+	} while (prepare_again);
 
 	return retval;
 }
@@ -1151,10 +1145,10 @@
 {
 	int retval;
 
-	//if (s->had_expunges)
+/* 	if (s->had_expunges) */
 		retval = camel_folder_summary_save_rewrite (s, ex);
-	//else
-	//	retval = camel_folder_summary_save_append (s, ex);
+/* 	else */
+/* 		retval = camel_folder_summary_save_append (s, ex); */
 
 	s->had_expunges = FALSE;
 
@@ -3759,6 +3753,10 @@
 	/* TODO: locking? */
 
 	old = mi->flags;
+	if (!(old & CAMEL_MESSAGE_INFO_NEEDS_FREE)
+	    && (flags & set))
+		mi->summary->had_expunges = TRUE;
+
 	mi->flags = (old & ~flags) | (set & flags);
 	if (old != mi->flags) {
 		mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 3168)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2007-12-21  Jose Dapena Paz  <jdapena igalia com>
+
+	* libtinymail-camel/camel-lite/camel/camel-folder-summary.c:
+        Use uid hash always when we try to fetch message info by uid.
+        Also small improvements for save_append operation. Not enough
+        yet to fix the operation, and then it's still disabled.
+
+
 2007-12-20  Alberto Garcia Gonzalez  <agarcia igalia com>
 
 	* libtinymail/tny-store-acount.c:


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