evolution-data-server r9034 - in branches/camel-db-summary/camel: . providers/local



Author: sragavan
Date: Tue Jun 24 13:00:00 2008
New Revision: 9034
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9034&view=rev

Log:
Use Camel pstring for UIDS. We save lot of memory there. Disable Unmatched folder. It seems to be a big culprit for memory and speed.
Also added pragma to keep memory of sqlite down.


Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-folder-summary.c
   branches/camel-db-summary/camel/camel-folder.c
   branches/camel-db-summary/camel/camel-string-utils.c
   branches/camel-db-summary/camel/camel-vee-folder.c
   branches/camel-db-summary/camel/camel-vee-store.c
   branches/camel-db-summary/camel/camel-vee-summary.c
   branches/camel-db-summary/camel/camel-vtrash-folder.c
   branches/camel-db-summary/camel/providers/local/camel-mbox-summary.c

Modified: branches/camel-db-summary/camel/camel-db.c
==============================================================================
--- branches/camel-db-summary/camel/camel-db.c	(original)
+++ branches/camel-db-summary/camel/camel-db.c	Tue Jun 24 13:00:00 2008
@@ -52,10 +52,16 @@
 		return NULL;
 	}
 
+
+
 	cdb = g_new (CamelDB, 1);
 	cdb->db = db;
 	cdb->lock = g_mutex_new ();
 	d(g_print ("\nDatabase succesfully opened  \n"));
+
+	#warning "make these under g_getenv"
+	camel_db_command (cdb, "PRAGMA cache_size=100", NULL) < 0);
+	
 	return cdb;
 }
 
@@ -318,7 +324,8 @@
 	table_creation_query = sqlite3_mprintf ("CREATE INDEX IF NOT EXISTS %Q ON %Q (vuid)", safe_index, folder_name);
 	ret = camel_db_command (db, table_creation_query, ex);
 
-	sqlite3_free (table_creation_query);	
+	sqlite3_free (table_creation_query);
+	g_free (safe_index);
 	return ret;	 
 }
 
@@ -337,7 +344,7 @@
 	 return ret;
 }
 
-static int 
+static int
 read_uids_callback (void *ref, int ncol, char ** cols, char ** name)
 {
 	 GPtrArray *array = (GPtrArray *)ref;
@@ -346,7 +353,7 @@
      #warning Sankar check if it is OK.
 	 for (i = 0; i < ncol; ++i) {
 		  if (!strcmp (name [i], "vuid"))
-			   g_ptr_array_add (array, g_strdup(cols [i]+8));
+			   g_ptr_array_add (array, camel_pstring_strdup(cols [i]+8));
 	 }
 	 
 	 return 0;
@@ -374,7 +381,7 @@
 	 printf("result = %d\n", array->len);
 	 /* We make sure to return NULL if we don't get anything. Be good to your caller */ 
 	 if (!array->len) {
-		  g_ptr_array_free (array, FALSE);
+		  g_ptr_array_free (array, TRUE);
 		  array = NULL;
 	 }
 
@@ -690,20 +697,20 @@
 camel_db_camel_mir_free (CamelMIRecord *record)
 {
 	if (record) {
-		g_free (record->uid);
-		g_free (record->subject);
-		g_free (record->from);
-		g_free (record->to);
-		g_free (record->cc);
-		g_free (record->mlist);
-		g_free (record->followup_flag);
-		g_free (record->followup_completed_on);
-		g_free (record->followup_due_by);
-		g_free (record->part);
-		g_free (record->labels);
-		g_free (record->usertags);
-		g_free (record->cinfo);
-		g_free (record->bdata);
+		camel_pstring_free (record->uid);
+		camel_pstring_free (record->subject);
+		camel_pstring_free (record->from);
+		camel_pstring_free (record->to);
+		camel_pstring_free (record->cc);
+		camel_pstring_free (record->mlist);
+		camel_pstring_free (record->followup_flag);
+		camel_pstring_free (record->followup_completed_on);
+		camel_pstring_free (record->followup_due_by);
+		camel_pstring_free (record->part);
+		camel_pstring_free (record->labels);
+		camel_pstring_free (record->usertags);
+		camel_pstring_free (record->cinfo);
+		camel_pstring_free (record->bdata);
 
 		g_free (record);
 	}

Modified: branches/camel-db-summary/camel/camel-folder-summary.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.c	(original)
+++ branches/camel-db-summary/camel/camel-folder-summary.c	Tue Jun 24 13:00:00 2008
@@ -194,7 +194,8 @@
 
 	p = _PRIVATE(obj);
 
-	camel_folder_summary_clear(s);
+	//camel_folder_summary_clear(s);
+	g_ptr_array_foreach (s->uids, camel_pstring_free, NULL);
 	g_ptr_array_free (s->uids, TRUE);
 	g_hash_table_destroy (s->loaded_infos);
 
@@ -446,7 +447,7 @@
 
 	g_ptr_array_set_size(res, s->uids->len);
 	for (i=0;i<s->uids->len;i++)
-		res->pdata[i] = g_ptr_array_index(s->uids, i);
+		res->pdata[i] = camel_pstring_strdup (g_ptr_array_index(s->uids, i));
 	
 
 	CAMEL_SUMMARY_UNLOCK(s, summary_lock);
@@ -655,20 +656,42 @@
 	return ci;
 }
 
-#warning "FIXME: I should have a better LRU algorithm "
 static void
+append_changed_uids (char *key, CamelMessageInfoBase *info, GPtrArray *array)
+{
+	if (info->dirty || info->flags & CAMEL_MESSAGE_FOLDER_FLAGGED)
+		g_ptr_array_add (array, camel_pstring_strdup((camel_message_info_uid(info))));
+}
+
+GPtrArray *
+camel_folder_summary_get_changed (CamelFolderSummary *s)
+{
+	GPtrArray *res = g_ptr_array_new();
+	
+	CAMEL_SUMMARY_LOCK (s, summary_lock);
+	g_hash_table_foreach (s->loaded_infos, append_changed_uids, res);
+	CAMEL_SUMMARY_UNLOCK (s, summary_lock);
+
+	return res;
+}
+
+#warning "FIXME: I should have a better LRU algorithm "
+static gboolean
 remove_item (char *key, CamelMessageInfo *info, CamelFolderSummary *s)
 {
 	d(printf("%d\t", info->refcount)); //camel_message_info_dump (info);
 	CAMEL_SUMMARY_LOCK(info->summary, ref_lock);
 	if (info->refcount == 1 && !info->dirty) {
-		CAMEL_SUMMARY_UNLOCK(info->summary, ref_lock);		
+		CAMEL_SUMMARY_UNLOCK(info->summary, ref_lock);
+		/* Hackit so that hashtable isn;t corrupted. */
+		camel_pstring_free (info->uid);
+		info->uid = NULL;
 		/* Noone seems to need it. Why not free it then. */
 		camel_message_info_free (info);
-		return;
+		return TRUE;
 	}
 	CAMEL_SUMMARY_UNLOCK(info->summary, ref_lock);	
-	return ;
+	return FALSE;
 }
 static gboolean      
 remove_cache (CamelFolderSummary *s)
@@ -677,7 +700,7 @@
 	d(printf("removing cache for  %s %d\n", s->folder->full_name, g_hash_table_size (s->loaded_infos)));
 	#warning "hack. fix it"
 	CAMEL_SUMMARY_LOCK (s, summary_lock);
-	g_hash_table_foreach  (s->loaded_infos, remove_item, s);
+	g_hash_table_foreach_remove  (s->loaded_infos, remove_item, s);
 	CAMEL_SUMMARY_UNLOCK (s, summary_lock);
 	d(printf("done .. now %d\n",g_hash_table_size (s->loaded_infos)));
 	return TRUE;
@@ -705,7 +728,7 @@
 	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer**) &s, camel_read_mir_callback, ex);
 
 	#warning "LRU please and not timeouts"
-	g_timeout_add_seconds (30, remove_cache, s);
+	g_timeout_add_seconds (40, remove_cache, s);
 	return ret;
 }
 
@@ -717,7 +740,7 @@
 	for (i = 0; i < ncol; ++i) {
 
 		if ( !strcmp (name [i], "uid") ) 
-			mir->uid = g_strdup (cols [i]);
+			mir->uid = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "flags") ) 
 			mir->flags = cols [i] ? strtoul (cols [i], NULL, 10) : 0;
 		else if ( !strcmp (name [i], "read") ) 
@@ -739,31 +762,31 @@
 		else if ( !strcmp (name [i], "dreceived") ) 
 			mir->dreceived = cols [i] ? strtol (cols [i], NULL, 10) : 0;
 		else if ( !strcmp (name [i], "subject") ) 
-			mir->subject = g_strdup (cols [i]);
+			mir->subject = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "mail_from") ) 
-			mir->from = g_strdup (cols [i]);
+			mir->from = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "mail_to") ) 
-			mir->to = g_strdup (cols [i]);
+			mir->to = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "mail_cc") ) 
-			mir->cc = g_strdup (cols [i]);
+			mir->cc = camel_pstring_strdup(cols [i]);
 		else if ( !strcmp (name [i], "mlist") ) 
-			mir->mlist = g_strdup (cols [i]);
+			mir->mlist = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "followup_flag") ) 
-			mir->followup_flag = g_strdup (cols [i]);
+			mir->followup_flag = camel_pstring_strdup(cols [i]);
 		else if ( !strcmp (name [i], "followup_completed_on") ) 
-			mir->followup_completed_on = g_strdup (cols [i]);
+			mir->followup_completed_on = camel_pstring_strdup(cols [i]);
 		else if ( !strcmp (name [i], "followup_due_by") ) 
-			mir->followup_due_by = g_strdup (cols [i]);
+			mir->followup_due_by = camel_pstring_strdup(cols [i]);
 		else if ( !strcmp (name [i], "part") ) 
-			mir->part = g_strdup (cols [i]);
+			mir->part = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "labels") ) 
-			mir->labels = g_strdup (cols [i]);
+			mir->labels = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "usertags") ) 
-			mir->usertags = g_strdup (cols [i]);
+			mir->usertags = camel_pstring_strdup (cols [i]);
 		else if ( !strcmp (name [i], "cinfo") ) 
-			mir->cinfo = g_strdup (cols [i]);
+			mir->cinfo = camel_pstring_strdup(cols [i]);
 		else if ( !strcmp (name [i], "bdata") ) 
-			mir->bdata = g_strdup (cols [i]);
+			mir->bdata = camel_pstring_strdup(cols [i]);
 
 	}	
 }
@@ -925,14 +948,13 @@
 perform_content_info_save_to_db (CamelFolderSummary *s, CamelMessageContentInfo *ci, CamelMIRecord *record)
 {
 	CamelMessageContentInfo *part;
-	char *oldr, *cnt;
+	char *oldr;
 	if (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->content_info_to_db (s, ci, record) == -1)
 		return -1;
 	
 	oldr = record->cinfo;
-	cnt = g_strdup_printf (" %d", my_list_size ((struct _node **)&ci->childs));
-	record->cinfo = g_strconcat (oldr, cnt, NULL);
-	g_free (oldr); g_free (cnt);
+	record->cinfo = g_strdup_printf ("%s %d", oldr, my_list_size ((struct _node **)&ci->childs));
+	g_free (oldr);
 
 	part = ci->childs;
 	while (part) {
@@ -1222,6 +1244,9 @@
 		ret = -1;
 	}
 
+	g_free (record->folder_name);
+	#warning "Crashes, take care"
+	//g_free (record->bdata); 
 	g_free (record);
 
 	return ret;
@@ -1281,8 +1306,8 @@
 	uid = camel_message_info_uid (info);
 
 	if (uid == NULL || uid[0] == 0) {
-		g_free (info->uid);
-		uid = info->uid = camel_folder_summary_next_uid_string(s);
+		camel_pstring_free (info->uid);
+		uid = info->uid = camel_pstring_add (camel_folder_summary_next_uid_string(s), TRUE);
 	}
 
 	CAMEL_SUMMARY_LOCK(s, summary_lock);
@@ -1295,7 +1320,7 @@
 
 		d(printf ("Trying to insert message with clashing uid (%s).  new uid re-assigned", camel_message_info_uid (info)));
 
-		g_free(info->uid);
+		camel_pstring_free (info->uid);
 		uid = info->uid = camel_folder_summary_next_uid_string(s);
 
 		camel_message_info_set_flags(info, CAMEL_MESSAGE_FOLDER_FLAGGED, CAMEL_MESSAGE_FOLDER_FLAGGED);
@@ -1344,7 +1369,7 @@
 	//camel_message_info_ref(info); //FIXME: Check how things are loaded.
 	#warning "FIXME: SHould we ref it or redesign it later on"
 	/* The uid array should have its own memory. We will unload the infos when not reqd.*/
-	g_ptr_array_add (s->uids, g_strdup(camel_message_info_uid(info)));
+	g_ptr_array_add (s->uids, camel_pstring_strdup((camel_message_info_uid(info))));
 	
 	g_hash_table_insert (s->loaded_infos, camel_message_info_uid (info), info);
 	s->flags |= CAMEL_SUMMARY_DIRTY;
@@ -1373,7 +1398,7 @@
 	#warning "FIXME: SHould we ref it or redesign it later on"
 	/* The uid array should have its own memory. We will unload the infos when not reqd.*/
 	if (!load)
-		g_ptr_array_add (s->uids, g_strdup(camel_message_info_uid(info)));
+		g_ptr_array_add (s->uids, camel_pstring_strdup(camel_message_info_uid(info)));
 	
 	g_hash_table_insert (s->loaded_infos, camel_message_info_uid (info), info);
 	if (!load)
@@ -1690,6 +1715,7 @@
 
 
 	camel_db_clear_folder_summary (cdb, folder_name, NULL);
+	g_ptr_array_foreach (s->uids, camel_pstring_free, NULL);
 	g_ptr_array_free (s->uids, TRUE);
 	s->uids = g_ptr_array_new ();
 
@@ -1722,6 +1748,7 @@
 		if (strcmp(s->uids->pdata[i], uid) == 0) {
 			/* FIXME: Does using fast remove affect anything ? */
 			g_ptr_array_remove_index(s->uids, i);
+			camel_pstring_free (uid);
 			break;
 		}
 
@@ -1800,6 +1827,7 @@
 	if (g_hash_table_lookup_extended(s->loaded_infos, uid, (void *)&olduid, (void *)&oldinfo)) {
 		/* make sure it doesn't vanish while we're removing it */
 		g_hash_table_remove (s->loaded_infos, uid);
+		camel_pstring_free (uid);
 		g_ptr_array_remove_index(s->uids, i);
 		CAMEL_SUMMARY_UNLOCK(s, ref_lock);
 		CAMEL_SUMMARY_UNLOCK(s, summary_lock);
@@ -1860,7 +1888,7 @@
 		for (i = start; i < end; i++) {
 			const char *uid = s->uids->pdata[i];
 
-			uids = g_slist_prepend (uids, g_strdup (uid));
+			uids = g_slist_prepend (uids, uid);
 
 			g_hash_table_remove(s->loaded_infos, uid);
 		}
@@ -1869,9 +1897,10 @@
 		folder_name = s->folder->full_name;
 		cdb = s->folder->parent_store->cdb;
 
+		#warning "lifecycle of infos should be checked. Add should add to db and del should del to db. Sync only the changes at interval and remove those full sync on folder switch"
 		camel_db_delete_uids (cdb, folder_name, uids, &ex);
 
-		g_slist_foreach (uids, (GFunc) g_free, NULL);
+		g_slist_foreach (uids, (GFunc) camel_pstring_free, NULL);
 		g_slist_free (uids);
 
 		memmove(s->uids->pdata+start, s->uids->pdata+end, (s->uids->len-end)*sizeof(s->uids->pdata[0]));
@@ -2512,7 +2541,7 @@
 	mi->date_sent = record->dsent;
 	mi->date_received = record->dreceived;
 
-	mi->uid = g_strdup (record->uid);
+	mi->uid = camel_pstring_strdup (record->uid);
 	mi->subject = camel_pstring_add (record->subject, FALSE);
 	mi->from = camel_pstring_add (record->from, FALSE);
 	mi->to = camel_pstring_add (record->to, FALSE);
@@ -2681,7 +2710,7 @@
 	int count, i;
 
 	/* Assume that we dont have to take care of DB Safeness. It will be done while doing the DB transaction */
-	record->uid = g_strdup(camel_message_info_uid(mi));
+	record->uid = camel_pstring_strdup(camel_message_info_uid(mi));
 	record->flags = mi->flags;
 	
 	record->read =  ((mi->flags & (CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_JUNK)));
@@ -2695,15 +2724,15 @@
 	record->dsent = mi->date_sent;
 	record->dreceived = mi->date_received;
 
-	record->subject = g_strdup(camel_message_info_subject (mi));
-	record->from = g_strdup(camel_message_info_from (mi));
-	record->to = g_strdup(camel_message_info_to (mi));
-	record->cc = g_strdup(camel_message_info_cc (mi));
-	record->mlist = g_strdup(camel_message_info_mlist (mi));
-	
-	record->followup_flag = g_strdup(camel_message_info_user_tag(info, "follow-up"));
-	record->followup_completed_on = g_strdup(camel_message_info_user_tag(info, "completed-on"));
- 	record->followup_due_by = g_strdup(camel_message_info_user_tag(info, "due-by"));
+	record->subject = camel_pstring_strdup(camel_message_info_subject (mi));
+	record->from = camel_pstring_strdup(camel_message_info_from (mi));
+	record->to = camel_pstring_strdup(camel_message_info_to (mi));
+	record->cc = camel_pstring_strdup(camel_message_info_cc (mi));
+	record->mlist = camel_pstring_strdup(camel_message_info_mlist (mi));
+	
+	record->followup_flag = camel_pstring_strdup(camel_message_info_user_tag(info, "follow-up"));
+	record->followup_completed_on = camel_pstring_strdup(camel_message_info_user_tag(info, "completed-on"));
+ 	record->followup_due_by = camel_pstring_strdup(camel_message_info_user_tag(info, "due-by"));
 
 	tmp = g_string_new (NULL);
 	if (mi->references) {
@@ -2809,7 +2838,7 @@
 	
 	if (mi->uid) {
 		g_hash_table_remove (s->loaded_infos, mi->uid);
-		g_free(mi->uid);
+		camel_pstring_free(mi->uid);
 	} 
 	camel_pstring_free(mi->subject);
 	camel_pstring_free(mi->from);
@@ -2887,6 +2916,7 @@
 	}
 	ci->type = ct;
 
+	#warning "move all these to camel pstring"
 	EXTRACT_STRING (ci->id);
 	EXTRACT_STRING (ci->description)
 	EXTRACT_STRING (ci->encoding)

Modified: branches/camel-db-summary/camel/camel-folder.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder.c	(original)
+++ branches/camel-db-summary/camel/camel-folder.c	Tue Jun 24 13:00:00 2008
@@ -43,6 +43,7 @@
 #include "camel-session.h"
 #include "camel-store.h"
 #include "camel-vtrash-folder.h"
+#include "camel-string-utils.h"
 
 #define d(x)
 #define w(x)
@@ -373,6 +374,11 @@
 						camel_message_info_free(info);
 					}
 				}
+
+				#warning "I added it for vfolders summary storage, does it harm ?"
+				folder->summary->junk_count = junked;
+				folder->summary->deleted_count = deleted;
+				folder->summary->unread_count = unread;
 			}
 
 			switch (tag & CAMEL_ARG_TAG) {
@@ -399,7 +405,7 @@
 			int j;
 			CamelMessageInfo *info;
 			GPtrArray *array;
-
+/*
 			count = camel_folder_summary_count(folder->summary);
 			array = g_ptr_array_new();
 			g_ptr_array_set_size(array, count);
@@ -409,7 +415,9 @@
 					camel_message_info_free(info);
 				}
 			}
-			*arg->ca_ptr = array;
+			*arg->ca_ptr = array;*/
+			// WTH this is reqd ?, let it crash to find out who uses this
+			printf("%s", 0);
 			break; }
 		case CAMEL_FOLDER_ARG_INFO_ARRAY:
 			*arg->ca_ptr = camel_folder_summary_array(folder->summary);
@@ -442,7 +450,7 @@
 		g_ptr_array_free(array, TRUE);
 		break; }
 	case CAMEL_FOLDER_ARG_INFO_ARRAY:
-		g_ptr_array_free((GPtrArray *)val, TRUE);
+		camel_folder_summary_array_free(folder->summary, val);
 		break;
 	case CAMEL_FOLDER_ARG_PROPERTIES:
 		g_slist_free(val);
@@ -1110,7 +1118,7 @@
 		CamelMessageInfo *info = camel_folder_summary_index(folder->summary, i);
 		
 		if (info) {
-			array->pdata[j++] = g_strdup (camel_message_info_uid (info));
+			array->pdata[j++] = camel_pstring_strdup (camel_message_info_uid (info));
 			camel_message_info_free(info);
 		}
 	}
@@ -1151,7 +1159,7 @@
 	int i;
 
 	for (i=0; i<array->len; i++)
-		g_free(array->pdata[i]);
+		camel_pstring_free(array->pdata[i]);
 	g_ptr_array_free(array, TRUE);
 }
 
@@ -1207,6 +1215,7 @@
 {
 	g_assert(folder->summary != NULL);
 
+	g_ptr_array_foreach (summary, camel_pstring_free, NULL);
 	g_ptr_array_free (summary, TRUE);
 }
 

Modified: branches/camel-db-summary/camel/camel-string-utils.c
==============================================================================
--- branches/camel-db-summary/camel/camel-string-utils.c	(original)
+++ branches/camel-db-summary/camel/camel-string-utils.c	Tue Jun 24 13:00:00 2008
@@ -245,6 +245,7 @@
 		}
 	} else {
 		g_warning("Trying to free string not allocated from the pool '%s'", s);
+		g_assert (0);
 	}
 	pthread_mutex_unlock(&pstring_lock);
 }

Modified: branches/camel-db-summary/camel/camel-vee-folder.c
==============================================================================
--- branches/camel-db-summary/camel/camel-vee-folder.c	(original)
+++ branches/camel-db-summary/camel/camel-vee-folder.c	Tue Jun 24 13:00:00 2008
@@ -43,6 +43,7 @@
 #include "camel-vee-folder.h"
 #include "camel-vee-store.h"	/* for open flags */
 #include "camel-vee-summary.h"
+#include "camel-string-utils.h"
 
 #define d(x) 
 #define dd(x) (camel_debug("vfolder")?(x):0)
@@ -665,7 +666,7 @@
 			}
 			
 		}
-		
+		camel_folder_free_summary (folder, summary);		
 	}
 
 
@@ -878,9 +879,12 @@
 						if (g_hash_table_lookup_extended(unmatched_uids, uid, (void **)&oldkey, &oldval)) {
 							n = GPOINTER_TO_INT (oldval);
 							if (n == 1) {
+								CamelMessageInfo *tinfo;
 								g_hash_table_remove(unmatched_uids, oldkey);
-								if (vee_folder_add_uid(folder_unmatched, source, oldkey+8, hash))
+								if (tinfo = vee_folder_add_uid(folder_unmatched, source, oldkey+8, hash)) {
+									camel_message_info_free (tinfo);
 									camel_folder_change_info_add_uid(folder_unmatched->changes, oldkey);
+								}
 								g_free(oldkey);
 							} else {
 								g_hash_table_insert(unmatched_uids, oldkey, GINT_TO_POINTER(n-1));
@@ -1144,9 +1148,10 @@
 	g_hash_table_destroy(matchhash);
 	g_hash_table_destroy(allhash);
 	/* if expression not set, we only had a null list */
-	if (vf->expression == NULL || !rebuilded)
+	if (vf->expression == NULL || !rebuilded) {
+		g_ptr_array_foreach (match, camel_pstring_free, NULL);
 		g_ptr_array_free(match, TRUE);
-	else
+	} else
 		camel_folder_search_free(f, match);
 	camel_folder_free_uids(f, all);
 

Modified: branches/camel-db-summary/camel/camel-vee-store.c
==============================================================================
--- branches/camel-db-summary/camel/camel-vee-store.c	(original)
+++ branches/camel-db-summary/camel/camel-vee-store.c	Tue Jun 24 13:00:00 2008
@@ -110,10 +110,13 @@
 	 ((CamelServiceClass *) camel_vee_store_parent)->construct(service, session, provider, url, ex);
 	 
 	/* Set up unmatched folder */
+#ifdef VEE_UNMATCHED_ENABLE
 	obj->unmatched_uids = g_hash_table_new (g_str_hash, g_str_equal);
 	obj->folder_unmatched = (CamelVeeFolder *)camel_object_new (camel_vee_folder_get_type ());
 	camel_vee_folder_construct (obj->folder_unmatched, store, CAMEL_UNMATCHED_NAME, _("Unmatched"), CAMEL_STORE_FOLDER_PRIVATE);
 	camel_db_create_vfolder (store->cdb, _("Unmatched"), NULL);
+#endif
+	 
 }
 static void
 cvs_free_unmatched(void *key, void *value, void *data)

Modified: branches/camel-db-summary/camel/camel-vee-summary.c
==============================================================================
--- branches/camel-db-summary/camel/camel-vee-summary.c	(original)
+++ branches/camel-db-summary/camel/camel-vee-summary.c	Tue Jun 24 13:00:00 2008
@@ -297,12 +297,19 @@
 /* 		return NULL; */
 /* 	} */
 
+	mi = message_info_from_uid(&s->summary, vuid); 
+	if (mi) {
+		g_warning ("%s - already there\n", vuid);
+		g_free (vuid);
+		return mi;
+	}
+
 	mi = (CamelVeeMessageInfo *)camel_message_info_new(&s->summary);
 	mi->summary = summary;
 	camel_object_ref (summary);
 	mi->info.uid = vuid;
-
+	camel_message_info_ref (mi);
 	camel_folder_summary_insert(&s->summary, (CamelMessageInfo *)mi, FALSE);
-
+	
 	return mi;
 }

Modified: branches/camel-db-summary/camel/camel-vtrash-folder.c
==============================================================================
--- branches/camel-db-summary/camel/camel-vtrash-folder.c	(original)
+++ branches/camel-db-summary/camel/camel-vtrash-folder.c	Tue Jun 24 13:00:00 2008
@@ -36,7 +36,7 @@
 #include "camel-store.h"
 #include "camel-vee-store.h"
 #include "camel-vtrash-folder.h"
-
+#include "camel-string-utils.h"
 
 /* Returns the class for a CamelFolder */
 #define CF_CLASS(so) ((CamelFolderClass *)((CamelObject *)(so))->klass)
@@ -48,11 +48,12 @@
 	guint32 bit;
 	guint32 flags;
 	const char *error_copy;
+	const char *db_col;
 } vdata[] = {
 	{ CAMEL_VTRASH_NAME, N_("Trash"), "(match-all (system-flag \"Deleted\"))", CAMEL_MESSAGE_DELETED, CAMEL_FOLDER_IS_TRASH,
-	  N_("Cannot copy messages to the Trash folder") },
+	  N_("Cannot copy messages to the Trash folder"), "deleted" },
 	{ CAMEL_VJUNK_NAME, N_("Junk"), "(match-all (system-flag \"Junk\"))", CAMEL_MESSAGE_JUNK, CAMEL_FOLDER_IS_JUNK,
-	  N_("Cannot copy messages to the Junk folder") },
+	  N_("Cannot copy messages to the Junk folder"), "junk" },
 };
 
 static CamelVeeFolderClass *camel_vtrash_folder_parent;
@@ -317,10 +318,12 @@
 				continue;
 			//if (camel_message_info_flags(mi) & ((CamelVTrashFolder *)folder)->bit)
 			if (vmi->summary == f->summary) /* Belongs to this folder */
-				g_ptr_array_add(uids, (void *)(infos->pdata[i]+8));
+				g_ptr_array_add(uids, (void *)camel_pstring_strdup(infos->pdata[i]+8));
 			camel_message_info_free (vmi);
 		}
 
+		camel_folder_free_summary (folder, infos);
+                #warning search in the DB of the folder, for the expression, with the vtrash bit (junk/trash)
 		if (uids->len > 0
 		    && (matches = camel_folder_search_by_uids(f, expression, uids, NULL))) {
 			for (i = 0; i < matches->len; i++) {
@@ -340,6 +343,7 @@
 
 	CAMEL_VEE_FOLDER_UNLOCK(folder, subfolder_lock);
 
+	g_ptr_array_foreach (uids, camel_pstring_free, NULL);
 	g_ptr_array_free(uids, TRUE);
 
 	return result;
@@ -363,19 +367,22 @@
 		camel_vee_folder_hash_folder(f, hash);
 
 		/* map the vfolder uid's to the source folder uid's first */
-		g_ptr_array_set_size(uids, 0);
+		#warning "check this. is it uids od folder_uids"
+		//g_ptr_array_set_size(uids, 0);
+		g_ptr_array_set_size (folder_uids, 0);
 		for (i=0;i<uids->len;i++) {
 			char *uid = uids->pdata[i];
 			
-			if (strlen(uid) >= 8 && strncmp(uid, hash, 8) == 0) {
-				CamelMessageInfo *mi;
-
-				mi = camel_folder_get_message_info(f, uid+8);
-				if (mi) {
-					if(camel_message_info_flags(mi) & ((CamelVTrashFolder *)folder)->bit)
+			//if (strlen(uid) >= 8 && strncmp(uid, hash, 8) == 0) {
+			if (strncmp(uid, hash, 8) == 0) {				
+				//CamelMessageInfo *mi;
+				#warning "is it really reqd, if so uncomment it"
+				//mi = camel_folder_get_message_info(f, uid+8);
+				//if (mi) {
+				//	if(camel_message_info_flags(mi) & ((CamelVTrashFolder *)folder)->bit)
 						g_ptr_array_add(folder_uids, uid+8);
-					camel_folder_free_message_info(f, mi);
-				}
+				//	camel_folder_free_message_info(f, mi);
+				//}
 			}
 		}
 
@@ -430,8 +437,12 @@
 	strcpy(vuid+8, uid);
 	vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid(((CamelFolder *)vf)->summary, vuid);
 	if (vinfo == NULL) {
-		camel_vee_summary_add((CamelVeeSummary *)((CamelFolder *)vf)->summary, binfo->summary, uid, hash);
-		camel_folder_change_info_add_uid(((CamelVeeFolder *)vf)->changes, vuid);
+		CamelMessageInfo *tinfo;
+		tinfo = camel_vee_summary_add((CamelVeeSummary *)((CamelFolder *)vf)->summary, binfo->summary, uid, hash);
+		if (tinfo) {
+			camel_folder_change_info_add_uid(((CamelVeeFolder *)vf)->changes, vuid);
+			camel_message_info_free (tinfo);
+		}
 	} else {
 		camel_folder_change_info_change_uid(((CamelVeeFolder *)vf)->changes, vuid);
 		camel_message_info_free(vinfo);
@@ -509,6 +520,7 @@
 
 	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
 
+	#warning "Search for deleted /junk uids in the db and add them directly"
 	infos = camel_folder_get_summary(sub);
 	for (i=0;i<infos->len;i++) {
 		CamelMessageInfo *info;
@@ -518,7 +530,8 @@
 			vtrash_uid_added((CamelVTrashFolder *)vf, uid, info, hash);
 		camel_message_info_free (info);
 	}
-	camel_folder_free_summary(sub, infos);
+	g_ptr_array_foreach (infos, camel_pstring_free, NULL);
+	g_ptr_array_free (infos, TRUE);
 
 	if (camel_folder_change_info_changed(vf->changes)) {
 		vf_changes = vf->changes;
@@ -553,7 +566,9 @@
 	for (i=0;i<infos->len;i++) {
 
 		CamelVeeMessageInfo *mi = (CamelVeeMessageInfo *) camel_folder_summary_uid (((CamelFolder *)vf)->summary, infos->pdata[i]);
-		if (mi == NULL || mi->summary == NULL) {
+		if (mi == NULL)
+			continue;
+		if (mi->summary == NULL) {
 			camel_message_info_free (mi);
 			continue;
 		}

Modified: branches/camel-db-summary/camel/providers/local/camel-mbox-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/local/camel-mbox-summary.c	(original)
+++ branches/camel-db-summary/camel/providers/local/camel-mbox-summary.c	Tue Jun 24 13:00:00 2008
@@ -779,7 +779,7 @@
 	const char *xev;
 	int len;
 	off_t lastpos;
-
+	GPtrArray *summary = NULL;
 	int mbox_file_is_corrupt = 0;
 
 	d(printf("Performing quick summary sync\n"));
@@ -811,16 +811,15 @@
 	camel_mime_parser_scan_pre_from(mp, TRUE);
 	camel_mime_parser_init_with_fd(mp, pfd);
 
-	count = camel_folder_summary_count(s);
-	for (i = 0; i < count; i++) {
+	/* Sync only the changes */
+	summary = camel_folder_summary_get_changed ((CamelFolderSummary *)mbs);
+	for (i = 0; i < summary->len; i++) {
 		int xevoffset;
 		int pc = (i+1)*100/count;
 
 		camel_operation_progress(NULL, pc);
 
-		info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i);
-
-		g_assert(info);
+		info = (CamelMboxMessageInfo *)camel_folder_summary_uid(s, summary->pdata[i]);
 
 		d(printf("Checking message %s %08x\n", camel_message_info_uid(info), info->info.flags));
 
@@ -943,12 +942,16 @@
 		goto error;
 	}
 
+	g_ptr_array_foreach (summary, camel_pstring_free, NULL);
+	g_ptr_array_free (summary, TRUE);
 	camel_object_unref((CamelObject *)mp);
 
 	camel_operation_end(NULL);
 	
 	return 0;
  error:
+	g_ptr_array_foreach (summary, camel_pstring_free, NULL);
+	g_ptr_array_free (summary, TRUE);	
 	if (fd != -1)
 		close(fd);
 	if (mp)
@@ -970,28 +973,40 @@
 	int i, count;
 	int quick = TRUE, work=FALSE;
 	int ret;
-
+	GPtrArray *summary = NULL;
+	
 	/* first, sync ourselves up, just to make sure */
 	if (camel_local_summary_check(cls, changeinfo, ex) == -1)
 		return -1;
 
-	count = camel_folder_summary_count(s);
-	if (count == 0)
-		return 0;
+	/* Sync only the changes */
 
-	/* check what work we have to do, if any */
-	for (i=0;quick && i<count; i++) {
-		CamelMboxMessageInfo *info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i);
 
-		g_assert(info);
+	summary = camel_folder_summary_get_changed ((CamelFolderSummary *)mbs);
+	for (i=0; i<summary->len; i++) {
+		CamelMboxMessageInfo *info = (CamelMboxMessageInfo *)camel_folder_summary_uids(s, summary->pdata[i]);
 		
 		if ((expunge && (info->info.info.flags & CAMEL_MESSAGE_DELETED)) ||
 		    (info->info.info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV|CAMEL_MESSAGE_FOLDER_XEVCHANGE)))
 			quick = FALSE;
 		else
 			work |= (info->info.info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0;
-		camel_message_info_free(info);
+		camel_message_info_free(info);		
+	}
+
+	g_ptr_array_foreach (summary, camel_pstring_free, NULL);
+	g_ptr_array_free (summary, TRUE);
+	
+	if (quick && expunge) {
+		int dcount =0;
+
+	
+		if (camel_db_count_deleted_message_info (s->folder->parent_store->cdb, s->folder->full_name, &dcount, ex) == -1)
+			return -1;
+		if (dcount)
+			quick = FALSE;
 	}
+	
 
 	/* yuck i hate this logic, but its to simplify the 'all ok, update summary' and failover cases */
 	ret = -1;



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