evolution-data-server r9072 - in branches/camel-db-summary/camel: . providers/imap



Author: sragavan
Date: Tue Jul  1 06:00:54 2008
New Revision: 9072
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9072&view=rev

Log:
Add option for g_slice and fix doubling of summary uids.


Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-db.h
   branches/camel-db-summary/camel/camel-folder-summary.c
   branches/camel-db-summary/camel/providers/imap/camel-imap-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 Jul  1 06:00:54 2008
@@ -13,7 +13,8 @@
 
 #define d(x)
 
-#define CAMEL_DB_SLEEP_INTERVAL 1*1000 
+#define CAMEL_DB_SLEEP_INTERVAL 1*10*10
+ 
 
 static int 
 cdb_sql_exec (sqlite3 *db, const char* stmt, CamelException *ex) 
@@ -663,7 +664,7 @@
 }
 
 int
-camel_db_read_message_info_record_with_uid (CamelDB *cdb, const char *folder_name, const char *uid, gpointer **p, CamelDBSelectCB read_mir_callback, CamelException *ex)
+camel_db_read_message_info_record_with_uid (CamelDB *cdb, const char *folder_name, const char *uid, gpointer p, CamelDBSelectCB read_mir_callback, CamelException *ex)
 {
 	char *query;
 	int ret;
@@ -676,7 +677,7 @@
 }
 
 int
-camel_db_read_message_info_records (CamelDB *cdb, const char *folder_name, gpointer **p, CamelDBSelectCB read_mir_callback, CamelException *ex)
+camel_db_read_message_info_records (CamelDB *cdb, const char *folder_name, gpointer p, CamelDBSelectCB read_mir_callback, CamelException *ex)
 {
 	char *query;
 	int ret;

Modified: branches/camel-db-summary/camel/camel-db.h
==============================================================================
--- branches/camel-db-summary/camel/camel-db.h	(original)
+++ branches/camel-db-summary/camel/camel-db.h	Tue Jul  1 06:00:54 2008
@@ -87,7 +87,7 @@
 
 
 typedef struct _CamelDB CamelDB;
-typedef int (*CamelDBSelectCB) (void *data, int ncol, char **colvalues, char **colnames);
+typedef int (*CamelDBSelectCB) (gpointer data, int ncol, char **colvalues, char **colnames);
 
 
 CamelDB * camel_db_open (const char *path, CamelException *ex);
@@ -116,8 +116,8 @@
 int camel_db_prepare_message_info_table (CamelDB *cdb, const char *folder_name, CamelException *ex);
 
 int camel_db_write_message_info_record (CamelDB *cdb, const char *folder_name, CamelMIRecord *record, CamelException *ex);
-int camel_db_read_message_info_records (CamelDB *cdb, const char *folder_name, gpointer **p, CamelDBSelectCB read_mir_callback, CamelException *ex);
-int camel_db_read_message_info_record_with_uid (CamelDB *cdb, const char *folder_name, const char *uid, gpointer **p, CamelDBSelectCB read_mir_callback, CamelException *ex);
+int camel_db_read_message_info_records (CamelDB *cdb, const char *folder_name, gpointer p, CamelDBSelectCB read_mir_callback, CamelException *ex);
+int camel_db_read_message_info_record_with_uid (CamelDB *cdb, const char *folder_name, const char *uid, gpointer p, CamelDBSelectCB read_mir_callback, CamelException *ex);
 
 int camel_db_count_junk_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex);
 int camel_db_count_unread_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex);

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 Jul  1 06:00:54 2008
@@ -63,7 +63,8 @@
 #include "camel-vee-folder.h"
 
 /* To switch between e-memchunk and g-alloc */
-#define ALWAYS_ALLOC
+#define ALWAYS_ALLOC 1
+#define USE_GSLICE 1
 #define SUMMARY_CACHE_DROP 120
 static pthread_mutex_t info_lock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -137,7 +138,6 @@
 static void camel_folder_summary_finalize   (CamelObject *obj);
 
 static CamelObjectClass *camel_folder_summary_parent;
-static int camel_read_one_mir_callback (void * ref, int ncol, char ** cols, char ** name);
 static CamelMessageInfo * message_info_from_uid (CamelFolderSummary *s, const char *uid);
 
 static void
@@ -458,6 +458,12 @@
 }
 
 
+struct _db_pass_data {
+	CamelFolderSummary *summary;
+	gboolean double_ref;
+	gboolean add; /* or just insert to hashtable */
+};
+
 static CamelMessageInfo *
 message_info_from_uid (CamelFolderSummary *s, const char *uid)
 {
@@ -473,7 +479,8 @@
 		CamelDB *cdb;
 		CamelException ex;// May be this should come from the caller 
 		char *folder_name;
-
+		struct _db_pass_data data;
+		
 		d(printf ("\ncamel_folder_summary_uid called \n"));
 		camel_exception_init (&ex);
 		s->flags &= ~CAMEL_SUMMARY_DIRTY;
@@ -483,7 +490,13 @@
 		
 		CAMEL_SUMMARY_UNLOCK(s, ref_lock);
 		CAMEL_SUMMARY_UNLOCK(s, summary_lock);
-		ret = camel_db_read_message_info_record_with_uid (cdb, folder_name, uid, (gpointer**) &s, camel_read_one_mir_callback, &ex);
+
+		data.summary = s;
+		data.double_ref = TRUE;
+		data.add = FALSE;
+
+	
+		ret = camel_db_read_message_info_record_with_uid (cdb, folder_name, uid, &data, camel_read_mir_callback, &ex);
 		if (ret != 0) {
 			// if (strcmp (folder_name, "UNMATCHED"))
 			g_warning ("Unable to read uid %s from folder %s: %s", uid, folder_name, camel_exception_get_description(&ex));
@@ -493,7 +506,7 @@
 		CAMEL_SUMMARY_LOCK(s, summary_lock);
 		CAMEL_SUMMARY_LOCK(s, ref_lock);
 
-		/* We would have double reffed at camel_read_one_mir_callback */
+		/* We would have double reffed at camel_read_mir_callback */
 		info = g_hash_table_lookup (s->loaded_infos, uid);
 		
 		if (!info) {
@@ -729,7 +742,8 @@
 	CamelDB *cdb;
 	char *folder_name;
 	int ret = 0;
-
+	struct _db_pass_data data;
+	
 	#warning "baseclass this, and vfolders we may have to load better."
 	d(printf ("\ncamel_folder_summary_reload_from_db called \n"));
 
@@ -737,7 +751,10 @@
 	cdb = s->folder->cdb;
 
 	/* FIXME FOR SANKAR: No need to pass the address of summary here. */
-	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer**) &s, camel_read_mir_callback, NULL);
+	data.summary = s;
+	data.double_ref = FALSE;
+	data.add = FALSE;
+	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer)&data, camel_read_mir_callback, NULL);
 
 	s->cache_load_time = time (NULL);
 	return ret == 0 ? 0 : -1;
@@ -750,7 +767,8 @@
 	CamelDB *cdb;
 	char *folder_name;
 	int ret = 0;
-
+	struct _db_pass_data data;
+	
 	d(printf ("\ncamel_folder_summary_load_from_db called \n"));
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
 
@@ -763,7 +781,10 @@
 	cdb = s->folder->cdb;
 
 	/* FIXME FOR SANKAR: No need to pass the address of summary here. */
-	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer**) &s, camel_read_mir_callback, ex);
+	data.summary = s;
+	data.add = TRUE;
+	data.double_ref = FALSE;
+	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer) &data, camel_read_mir_callback, ex);
 	s->cache_load_time = time (NULL);
 	#warning "LRU please and not timeouts"
 	g_timeout_add_seconds (SUMMARY_CACHE_DROP, remove_cache, s);
@@ -833,7 +854,8 @@
 static int 
 camel_read_mir_callback (void * ref, int ncol, char ** cols, char ** name)
 {
-	CamelFolderSummary *s = * (CamelFolderSummary **) ref;
+	struct _db_pass_data *data = (struct _db_pass_data *) ref;
+	CamelFolderSummary *s = data->summary;
 	CamelMIRecord *mir;
 	CamelMessageInfo *info;
 	int i;
@@ -868,55 +890,18 @@
 			mir->cinfo = tmp;
 		}
 
+		if (data->double_ref)
+			/* double reffing, because, at times frees before, I could read it. so we dont ref and give it again, just use it */		
+			camel_message_info_ref(info);
+		
 		/* Just now we are reading from the DB, it can't be dirty. */
 		((CamelMessageInfoBase *)info)->dirty = FALSE;
-//		((CamelMessageInfoBase *)info)->flags &= ~CAMEL_MESSAGE_DB_DIRTY;
-		camel_folder_summary_add (s, info);
-
-	} else {
-		g_warning ("Loading messageinfo from db failed");
-		ret = -1;
-	}
-
-	camel_db_camel_mir_free (mir);
-
-	return ret;
-}
-
-static int 
-camel_read_one_mir_callback (void * ref, int ncol, char ** cols, char ** name)
-{
-	CamelFolderSummary *s = * (CamelFolderSummary **) ref;
-	CamelMIRecord *mir;
-	CamelMessageInfo *info;
-	int i;
-
-	mir = g_new0 (CamelMIRecord , 1);
-
-	mir_from_cols (mir, s, ncol, cols, name);
-	
-	info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_from_db (s, mir);
+		//((CamelMessageInfoBase *)info)->flags &= ~CAMEL_MESSAGE_DB_DIRTY;		
+		if (data->add)
+			camel_folder_summary_add (s, info);
+		else
+			camel_folder_summary_insert (s, info, TRUE);
 
-	if (info) {
-		if (s->build_content) {
-			char *tmp;
-			tmp = mir->cinfo;			
-			/* FIXME: this should be done differently, how i don't know */
-			((CamelMessageInfoBase *)info)->content = perform_content_info_load_from_db (s, mir);
-			if (((CamelMessageInfoBase *)info)->content == NULL) {
-				camel_message_info_free(info);
-				info = NULL;
-			}
-			mir->cinfo = tmp;			
-		}
-
-		/* Just now we are reading from the DB, it can't be dirty. */
-		((CamelMessageInfoBase *)info)->dirty = FALSE;
-		//((CamelMessageInfoBase *)info)->flags &= ~CAMEL_MESSAGE_DB_DIRTY;
-		/* double reffing, because, at times frees before, I could read it. */		
-		camel_message_info_ref(info);
-		d(g_print ("\nAdding messageinfo to db from db \n"));
-		camel_folder_summary_insert (s, info, TRUE);
 	} else
 		g_warning ("Loading messageinfo from db failed");
 
@@ -2465,7 +2450,11 @@
 		s->content_info_chunks = e_memchunk_new(32, s->content_info_size);
 	ci = e_memchunk_alloc(s->content_info_chunks);
 #else	
+#ifndef USE_GSLICE
 	ci = g_malloc (s->content_info_size);
+#else	
+	ci = g_slice_alloc (s->content_info_size);
+#endif	
 #endif	
 	CAMEL_SUMMARY_UNLOCK(s, alloc_lock);
 
@@ -2912,11 +2901,19 @@
 	if (s)
 #ifndef ALWAYS_ALLOC
 		e_memchunk_free(s->message_info_chunks, mi);		
-#else		
+#else
+#ifndef USE_GSLICE	
 		g_free(mi);
+#else		
+	        g_slice_free1 (s->message_info_size, mi);
+#endif		
 #endif
 	else
+#ifndef USE_GSLICE
 		g_free(mi);
+#else		
+		g_slice_free (CamelMessageInfoBase, mi);
+#endif		
 }
 
 static CamelMessageContentInfo *
@@ -3142,8 +3139,13 @@
 	g_free(ci->encoding);
 #ifndef ALWAYS_ALLOC	
 	e_memchunk_free(s->content_info_chunks, ci);
-#endif	
+#else
+#ifndef USE_GSLICE	
 	g_free(ci);
+#else	
+	g_slice_free1 (s->content_info_size, ci);
+#endif	
+#endif	
 }
 
 static char *
@@ -3784,12 +3786,22 @@
 		if (s->message_info_chunks == NULL)
 			s->message_info_chunks = e_memchunk_new(32, s->message_info_size);
 		info = e_memchunk_alloc0(s->message_info_chunks);
-#else		
+#else
+#ifndef USE_GSLICE		
 		info = g_malloc0(s->message_info_size);
+#else		
+		info = g_slice_alloc0 (s->message_info_size);
+#endif		
 #endif		
 		CAMEL_SUMMARY_UNLOCK(s, alloc_lock);
 	} else {
+#ifndef USE_GSLICE		
 		info = g_malloc0(sizeof(CamelMessageInfoBase));
+#else		
+		info = g_slice_alloc0 (sizeof(CamelMessageInfoBase));
+#endif
+
+		
 	}
 
 	info->refcount = 1;

Modified: branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c	(original)
+++ branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c	Tue Jul  1 06:00:54 2008
@@ -409,7 +409,7 @@
 	}
 
 	mi->info.size = camel_message_info_size(info);
-	mi->info.uid = g_strdup (uid);
+	mi->info.uid = camel_pstring_strdup (uid);
 
 	camel_folder_summary_add (summary, (CamelMessageInfo *)mi);
 }



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