evolution-data-server r9679 - branches/gnome-2-24/camel



Author: sragavan
Date: Thu Oct 16 04:12:42 2008
New Revision: 9679
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9679&view=rev

Log:
2008-10-16  Srinivasa Ragavan  <sragavan novell com>

	** Fix for bug #556495

	* camel/camel-db.c:
	* camel/camel-db.h:
	* camel/camel-vee-folder.c: When things don't match, remove them from
	db and force a count.




Modified:
   branches/gnome-2-24/camel/ChangeLog
   branches/gnome-2-24/camel/camel-db.c
   branches/gnome-2-24/camel/camel-db.h
   branches/gnome-2-24/camel/camel-vee-folder.c

Modified: branches/gnome-2-24/camel/camel-db.c
==============================================================================
--- branches/gnome-2-24/camel/camel-db.c	(original)
+++ branches/gnome-2-24/camel/camel-db.c	Thu Oct 16 04:12:42 2008
@@ -920,8 +920,8 @@
 	return ret;
 }
 
-int
-camel_db_delete_uids (CamelDB *cdb, const char * folder_name, GSList *uids, CamelException *ex)
+static int
+cdb_delete_ids (CamelDB *cdb, const char * folder_name, GSList *uids, char *uid_prefix, const char *field, CamelException *ex)
 {
 	char *tmp;
 	int ret;
@@ -929,14 +929,16 @@
 	GString *str = g_string_new ("DELETE FROM ");
 	GSList *iterator;
 
-	tmp = sqlite3_mprintf ("%Q WHERE uid IN (", folder_name); 
+	tmp = sqlite3_mprintf ("%Q WHERE %s IN (", folder_name, field); 
 	g_string_append_printf (str, "%s ", tmp);
 	sqlite3_free (tmp);
 
 	iterator = uids;
 
 	while (iterator) {
-		tmp = sqlite3_mprintf ("%Q", (char *) iterator->data);
+		char *foo = g_strdup_printf("%s%s", uid_prefix, (char *) iterator->data);
+		tmp = sqlite3_mprintf ("%Q", foo);
+		g_free(foo);
 		iterator = iterator->next;
 
 		if (first == TRUE) {
@@ -958,6 +960,18 @@
 }
 
 int
+camel_db_delete_uids (CamelDB *cdb, const char * folder_name, GSList *uids, CamelException *ex)
+{
+	return cdb_delete_ids (cdb, folder_name, uids, "", "uid", ex);
+}
+
+int
+camel_db_delete_vuids (CamelDB *cdb, const char * folder_name, char *hash, GSList *uids, CamelException *ex)
+{
+	return cdb_delete_ids (cdb, folder_name, uids, hash, "vuid", ex);
+}
+
+int
 camel_db_clear_folder_summary (CamelDB *cdb, char *folder, CamelException *ex)
 {
 	int ret;

Modified: branches/gnome-2-24/camel/camel-db.h
==============================================================================
--- branches/gnome-2-24/camel/camel-db.h	(original)
+++ branches/gnome-2-24/camel/camel-db.h	Thu Oct 16 04:12:42 2008
@@ -121,6 +121,7 @@
 int camel_db_delete_uid (CamelDB *cdb, const char *folder, const char *uid, CamelException *ex);
 /*int camel_db_delete_uids (CamelDB *cdb, CamelException *ex, int nargs, ... );*/
 int camel_db_delete_uids (CamelDB *cdb, const char* folder_name, GSList *uids, CamelException *ex);
+int camel_db_delete_vuids (CamelDB *cdb, const char* folder_name, char *shash, GSList *uids, CamelException *ex);
 
 int camel_db_create_folders_table (CamelDB *cdb, CamelException *ex);
 int camel_db_select (CamelDB *cdb, const char* stmt, CamelDBSelectCB callback, gpointer data, CamelException *ex);

Modified: branches/gnome-2-24/camel/camel-vee-folder.c
==============================================================================
--- branches/gnome-2-24/camel/camel-vee-folder.c	(original)
+++ branches/gnome-2-24/camel/camel-vee-folder.c	Thu Oct 16 04:12:42 2008
@@ -1060,7 +1060,8 @@
 vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex)
 {
 	GPtrArray *match, *all;
-	GHashTable *allhash, *matchhash;
+	GHashTable *allhash, *matchhash, *fullhash;
+	GSList *del_list = NULL;
 	CamelFolder *f = source;
 	CamelFolder *folder = (CamelFolder *)vf;
 	int i, n, count, start, last;
@@ -1118,10 +1119,25 @@
 		g_hash_table_insert(matchhash, match->pdata[i], GINT_TO_POINTER (1));
 
 	allhash = g_hash_table_new(g_str_hash, g_str_equal);
+	fullhash = g_hash_table_new(g_str_hash, g_str_equal);
 	all = camel_folder_summary_array(f->summary);
-	for (i=0;i<all->len;i++)
+	for (i=0;i<all->len;i++) {
 		if (g_hash_table_lookup(matchhash, all->pdata[i]) == NULL)
 			g_hash_table_insert(allhash, all->pdata[i], GINT_TO_POINTER (1));
+		g_hash_table_insert(fullhash, all->pdata[i], GINT_TO_POINTER (1));
+	
+	}
+	count = match->len;
+	for (i=0; i<count; i++) {
+		if (!g_hash_table_lookup(fullhash, match->pdata[i])) {
+			g_hash_table_remove (matchhash, match->pdata[i]);
+			del_list = g_slist_prepend (del_list, match->pdata[i]); /* Free the original */
+			g_ptr_array_remove_index_fast (match, i);
+			i--;
+			count--;
+			continue;
+		}	
+	}
 
 	if (folder_unmatched != NULL)
 		CAMEL_VEE_FOLDER_LOCK(folder_unmatched, summary_lock);
@@ -1220,9 +1236,19 @@
 	}
 
 	CAMEL_VEE_FOLDER_UNLOCK(vf, summary_lock);
+	
+	/* Del the unwanted things from the summary, we don't hold any locks now. */
+	if (del_list) {
+		camel_db_delete_vuids(folder->parent_store->cdb_w, folder->full_name, shash, del_list, NULL);
+		((CamelVeeSummary *)folder->summary)->force_counts = TRUE;
+		g_slist_foreach (del_list, (GFunc) camel_pstring_free, NULL);
+		g_slist_free (del_list);	
+	};
 
 	g_hash_table_destroy(matchhash);
 	g_hash_table_destroy(allhash);
+	g_hash_table_destroy(fullhash);
+
 	g_free(shash);
 	/* if expression not set, we only had a null list */
 	if (vf->expression == NULL || !rebuilded) {



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