evolution-data-server r9281 - trunk/camel



Author: sragavan
Date: Wed Aug  6 11:34:44 2008
New Revision: 9281
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9281&view=rev

Log:
2008-08-06  Srinivasa Ragavan  <sragavan novell com>

	* camel/camel-vee-folder.c: Redo vfolders. It now works.
	* camel/camel-vee-folder.h:
	* camel/camel-vee-summary.c:
	* camel/camel-vtrash-folder.c:


Modified:
   trunk/camel/ChangeLog
   trunk/camel/camel-vee-folder.c
   trunk/camel/camel-vee-folder.h
   trunk/camel/camel-vee-summary.c
   trunk/camel/camel-vtrash-folder.c

Modified: trunk/camel/camel-vee-folder.c
==============================================================================
--- trunk/camel/camel-vee-folder.c	(original)
+++ trunk/camel/camel-vee-folder.c	Wed Aug  6 11:34:44 2008
@@ -943,13 +943,16 @@
 	GHashTable *unmatched_uids = vf->parent_vee_store ? vf->parent_vee_store->unmatched_uids : NULL;
 	CamelFolderSummary *ssummary = source->summary;
 	gboolean rebuilded = FALSE;
+	char *shash; 
 	
 	if (vf == folder_unmatched)
 		return 0;
 
-	#warning "Reframe these lines later on"
 	camel_vee_folder_hash_folder(source, u.hash);
-	
+	shash = g_strdup_printf("%c%c%c%c%c%c%c%c", u.hash[0], u.hash[1], u.hash[2], u.hash[3], u.hash[4], u.hash[5], u.hash[6], u.hash[7]);	
+	if (!g_hash_table_lookup (vf->hashes, shash))
+		g_hash_table_insert (vf->hashes, g_strdup(shash), source->summary);
+
 	/* if we have no expression, or its been cleared, then act as if no matches */
 	if (vf->expression == NULL) {
 		match = g_ptr_array_new();
@@ -1086,6 +1089,7 @@
 
 	g_hash_table_destroy(matchhash);
 	g_hash_table_destroy(allhash);
+	g_free(shash);
 	/* if expression not set, we only had a null list */
 	if (vf->expression == NULL || !rebuilded) {
 		g_ptr_array_foreach (match, (GFunc) camel_pstring_free, NULL);
@@ -1118,6 +1122,7 @@
 static void
 folder_changed_add_uid(CamelFolder *sub, const char *uid, const char hash[8], CamelVeeFolder *vf)
 {
+	CamelFolder *folder = (CamelFolder *)vf;	
 	CamelVeeMessageInfo *vinfo;
 	const char *vuid;
 	char *oldkey;
@@ -1131,6 +1136,7 @@
 		return;
 	
 	vuid = camel_message_info_uid(vinfo);
+	camel_db_add_to_vfolder_transaction (folder->parent_store->cdb, folder->full_name, (char *)vuid, NULL);
 	camel_folder_change_info_add_uid(vf->changes,  vuid);
 
 	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER(sub) && folder_unmatched != NULL) {
@@ -1164,14 +1170,10 @@
 	memcpy(vuid, hash, 8);
 	strcpy(vuid+8, uid);
 
-	vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid(folder->summary, vuid);
-	if (vinfo) {
-		camel_folder_change_info_remove_uid(vf->changes, vuid);
-                #warning "Handle exception"
-		camel_db_delete_uid_from_vfolder (folder->parent_store->cdb, folder->full_name, vuid, NULL);
-		camel_folder_summary_remove(folder->summary, (CamelMessageInfo *)vinfo);
-		camel_message_info_free((CamelMessageInfo *)vinfo);
-	}
+	camel_folder_change_info_remove_uid(vf->changes, vuid);
+        #warning "Handle exception"
+	camel_db_delete_uid_from_vfolder_transaction (folder->parent_store->cdb, folder->full_name, vuid, NULL);
+	camel_folder_summary_remove_uid(folder->summary, vuid);
 
 	if ((vf->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0 && !CAMEL_IS_VEE_FOLDER(sub) && folder_unmatched != NULL) {
 		if (keep) {
@@ -1284,6 +1286,7 @@
 
 	camel_vee_folder_hash_folder(sub, hash);
 
+
 	/* Lookup anything before we lock anything, to avoid deadlock with build_folder */
 
 	/* Find newly added that match */
@@ -1328,6 +1331,9 @@
 	}
 
 	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
+	if (changes->uid_added->len || changes->uid_removed->len || changes->uid_changed->len)
+		camel_db_begin_transaction (folder->parent_store->cdb, NULL);
+
 	if (folder_unmatched != NULL)
 		CAMEL_VEE_FOLDER_LOCK(folder_unmatched, summary_lock);
 
@@ -1446,6 +1452,8 @@
 		vf->changes = camel_folder_change_info_new();
 	}
 
+	if (changes->uid_added->len || changes->uid_removed->len || changes->uid_changed->len)
+		camel_db_end_transaction (folder->parent_store->cdb, NULL);
 	CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
 
 	/* Cleanup stuff on our folder */
@@ -1670,7 +1678,15 @@
 static void
 vee_remove_folder(CamelVeeFolder *vf, CamelFolder *sub)
 {
+	char *shash, hash[8];
+
+	camel_vee_folder_hash_folder(sub, hash);	
 	vee_folder_remove_folder(vf, sub);
+	shash = g_strdup_printf("%c%c%c%c%c%c%c%c", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7]);
+	if (g_hash_table_lookup (vf->hashes, shash))
+		g_hash_table_remove (vf->hashes, shash);
+	g_free(shash);
+
 }
 
 static void
@@ -1691,7 +1707,10 @@
 	g_free(vf->expression);
 	if (query)
 		vf->expression = g_strdup(query);
-	#warning "reset the DB, err drop the table, . as the expression changed"
+
+	/* Recreate the table when the query changes. */
+	camel_db_recreate_vfolder (((CamelFolder *) vf)->parent_store->cdb, ((CamelFolder *) vf)->full_name, NULL);
+
 	node = p->folders;
 	while (node) {
 		CamelFolder *f = node->data;
@@ -1762,7 +1781,7 @@
 
 	obj->changes = camel_folder_change_info_new();
 	obj->search = camel_folder_search_new();
-	
+	obj->hashes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 	p->summary_lock = g_mutex_new();
 	p->subfolder_lock = g_mutex_new();
 	p->changed_lock = g_mutex_new();
@@ -1805,6 +1824,6 @@
 	g_mutex_free(p->summary_lock);
 	g_mutex_free(p->subfolder_lock);
 	g_mutex_free(p->changed_lock);
-	
+	g_hash_table_destroy (vf->hashes);
 	g_free(p);
 }

Modified: trunk/camel/camel-vee-folder.h
==============================================================================
--- trunk/camel/camel-vee-folder.h	(original)
+++ trunk/camel/camel-vee-folder.h	Wed Aug  6 11:34:44 2008
@@ -51,6 +51,7 @@
 	/* only set-up if our parent is a vee-store, used also as a flag to
 	 * say that this folder is part of the unmatched folder */
 	struct _CamelVeeStore *parent_vee_store;
+	GHashTable *hashes;
 };
 
 struct _CamelVeeFolderClass {

Modified: trunk/camel/camel-vee-summary.c
==============================================================================
--- trunk/camel/camel-vee-summary.c	(original)
+++ trunk/camel/camel-vee-summary.c	Wed Aug  6 11:34:44 2008
@@ -32,6 +32,7 @@
 #include "camel-folder.h"
 #include "camel-store.h"
 #include "camel-vee-summary.h"
+#include "camel-vee-folder.h"
 #include "camel-private.h"
 #include "camel-string-utils.h"
 
@@ -182,7 +183,7 @@
 static CamelMessageInfo *
 message_info_from_uid (CamelFolderSummary *s, const char *uid)
 {
-	CamelMessageInfoBase *info;
+	CamelMessageInfo *info;
 
 	#warning "too bad design. Need to peek it from cfs instead of hacking ugly like this"
 	CAMEL_SUMMARY_LOCK(s, summary_lock);
@@ -195,8 +196,24 @@
 
 	CAMEL_SUMMARY_UNLOCK(s, ref_lock);
 	CAMEL_SUMMARY_UNLOCK(s, summary_lock);
-
-	return (CamelMessageInfo *) info;	
+	
+	if (!info) {
+		CamelVeeMessageInfo *vinfo;
+		char tmphash[9];
+		
+		/* Create the info and load it, its so easy. */
+		info = camel_message_info_new (s);
+		camel_message_info_ref(info);
+		info->dirty = FALSE;
+		vinfo = (CamelVeeMessageInfo *) info;
+		info->uid = camel_pstring_strdup(uid);
+		strncpy(tmphash, uid, 8);
+		tmphash[8] = 0;
+		vinfo->summary = g_hash_table_lookup(((CamelVeeFolder *) s->folder)->hashes, tmphash);
+		camel_object_ref (vinfo->summary);
+		camel_folder_summary_insert (s, info, FALSE);
+	}
+	return info;	
 }
 
 static void
@@ -305,19 +322,19 @@
 	memcpy(vuid, hash, 8);
 	strcpy(vuid+8, uid);
 
-	/* We really dont need it. */
-/* 	mi = (CamelVeeMessageInfo *)camel_folder_summary_uid(&s->summary, vuid); */
-/* 	if (mi) { */
-/* 		d(printf("w:clash, we already have '%s' in summary\n", vuid)); */
-/* 		camel_message_info_free((CamelMessageInfo *)mi); */
-/* 		g_free(vuid); */
-/* 		return NULL; */
-/* 	} */
+	CAMEL_SUMMARY_LOCK(s, summary_lock);
+	mi = (CamelVeeMessageInfo *) g_hash_table_lookup(((CamelFolderSummary *) s)->loaded_infos, vuid); 
+	CAMEL_SUMMARY_UNLOCK(s, summary_lock);
 
-	mi = (CamelVeeMessageInfo *) message_info_from_uid(&s->summary, vuid); 
 	if (mi) {
-		g_warning ("%s - already there\n", vuid);
+		/* Possible that the entry is loaded, see if it has the summary */
+		g_message ("%s - already there\n", vuid);
 		g_free (vuid);
+		if (!mi->summary) {
+			mi->summary = summary;
+			camel_object_ref(summary);
+		}
+
 		return mi;
 	}
 

Modified: trunk/camel/camel-vtrash-folder.c
==============================================================================
--- trunk/camel/camel-vtrash-folder.c	(original)
+++ trunk/camel/camel-vtrash-folder.c	Wed Aug  6 11:34:44 2008
@@ -413,17 +413,12 @@
 vtrash_uid_removed(CamelVTrashFolder *vf, const char *uid, char hash[8])
 {
 	char *vuid;
-	CamelVeeMessageInfo *vinfo;
 
 	vuid = g_alloca(strlen(uid)+9);
 	memcpy(vuid, hash, 8);
 	strcpy(vuid+8, uid);
-	vinfo = (CamelVeeMessageInfo *)camel_folder_summary_uid(((CamelFolder *)vf)->summary, vuid);
-	if (vinfo) {
-		camel_folder_change_info_remove_uid(((CamelVeeFolder *)vf)->changes, vuid);
-		camel_folder_summary_remove(((CamelFolder *)vf)->summary, (CamelMessageInfo *)vinfo);
-		camel_message_info_free(vinfo);
-	}
+	camel_folder_change_info_remove_uid(((CamelVeeFolder *)vf)->changes, vuid);
+	camel_folder_summary_remove_uid(((CamelFolder *)vf)->summary, vuid);
 }
 
 static void
@@ -443,9 +438,6 @@
 			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);
 	}
 }
 
@@ -513,14 +505,16 @@
 {
 	GPtrArray *infos=NULL;
 	int i;
-	char hash[8];
+	char hash[8], *shash;
 	CamelFolderChangeInfo *vf_changes = NULL;
 
 	camel_vee_folder_hash_folder(sub, hash);
-
+	shash = g_strdup_printf("%c%c%c%c%c%c%c%c", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7]);
+	if (!g_hash_table_lookup (vf->hashes, shash))
+		g_hash_table_insert (vf->hashes, g_strdup(shash), sub->summary);
+	
 	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
 
-	#warning "Search for deleted /junk uids in the db and add them directly"
 	if (((CamelVTrashFolder *)vf)->bit == CAMEL_MESSAGE_DELETED)
 		infos = camel_db_get_folder_deleted_uids (sub->cdb, sub->full_name, NULL);
 	else if (((CamelVTrashFolder *)vf)->bit == CAMEL_MESSAGE_JUNK)
@@ -528,6 +522,7 @@
 
 	if (!infos) {
 		CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
+		g_free (shash);
 		return;
 	}
 	
@@ -550,6 +545,8 @@
 		camel_object_trigger_event(vf, "folder_changed", vf_changes);
 		camel_folder_change_info_free(vf_changes);
 	}
+
+	g_free(shash);
 }
 
 static void
@@ -557,12 +554,12 @@
 {
 	GPtrArray *infos;
 	int i;
-	char hash[8];
+	char hash[8], *shash;
 	CamelFolderChangeInfo *vf_changes = NULL;
 	CamelFolderSummary *ssummary = sub->summary;
 	int start, last;
 
-	camel_vee_folder_hash_folder(sub, hash);
+
 
 	CAMEL_VEE_FOLDER_LOCK(vf, summary_lock);
 
@@ -608,6 +605,11 @@
 
 	CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
 
+	camel_vee_folder_hash_folder(sub, hash);
+	shash = g_strdup_printf("%c%c%c%c%c%c%c%c", hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7]);
+	if (g_hash_table_lookup (vf->hashes, shash))
+		g_hash_table_remove (vf->hashes, shash);
+	g_free(shash);	
 	if (vf_changes) {
 		camel_object_trigger_event(vf, "folder_changed", vf_changes);
 		camel_folder_change_info_free(vf_changes);



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