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



Author: sragavan
Date: Thu Jun 26 10:10:04 2008
New Revision: 9051
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9051&view=rev

Log:
Makde DB perfolder.


Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-folder-search.c
   branches/camel-db-summary/camel/camel-folder-summary.c
   branches/camel-db-summary/camel/camel-folder.c
   branches/camel-db-summary/camel/camel-folder.h
   branches/camel-db-summary/camel/camel-vee-summary.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	Thu Jun 26 10:10:04 2008
@@ -12,13 +12,21 @@
 
 #define d(x)
 
+#define CAMEL_DB_SLEEP_INTERVAL 2
+
 static int 
 cdb_sql_exec (sqlite3 *db, const char* stmt, CamelException *ex) 
 {
   	char *errmsg;
-  	int   ret;
+  	int   ret = -1;
 
-  	ret = sqlite3_exec(db, stmt, 0, 0, &errmsg);
+	while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED || ret == -1) {
+		 if (ret != -1)
+			  sleep (CAMEL_DB_SLEEP_INTERVAL);
+		 
+		 ret = sqlite3_exec(db, stmt, 0, 0, &errmsg);
+	}
+	
 	d(g_print("%s\n", stmt));
   	if (ret != SQLITE_OK) {
 		 d(g_print ("Error in SQL EXEC statement: %s [%s].\n", stmt, errmsg));
@@ -192,10 +200,16 @@
 static int
 camel_db_count_message_info (CamelDB *cdb, const char *query, guint32 *count, CamelException *ex)
 {
-	int ret;
+	int ret = -1;
 	char *errmsg;
 
-	ret = sqlite3_exec (cdb->db, query, count_cb, count, &errmsg);
+	while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED || ret == -1) {
+		 if (ret != -1)
+			  sleep (CAMEL_DB_SLEEP_INTERVAL);
+		 ret = sqlite3_exec (cdb->db, query, count_cb, count, &errmsg);
+
+	}
+	
 	if (ret != SQLITE_OK) {
     		g_print ("Error in SQL SELECT statement: %s [%s]\n", query, errmsg);
 		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _(errmsg));
@@ -213,7 +227,7 @@
 		return -1;
 
 	char *query;
-	query = sqlite3_mprintf ("SELECT COUNT (junk) FROM %Q WHERE junk = 1", table_name);
+	query = sqlite3_mprintf ("SELECT COUNT (*) FROM %Q WHERE junk = 1", table_name);
 
 	ret = camel_db_count_message_info (cdb, query, count, ex);
 	sqlite3_free (query);
@@ -230,7 +244,41 @@
 		return -1;
 
 	char *query;
-	query = sqlite3_mprintf ("SELECT COUNT (read) FROM %Q WHERE read = 0", table_name);
+	query = sqlite3_mprintf ("SELECT COUNT (*) FROM %Q WHERE read = 0", table_name);
+
+	ret = camel_db_count_message_info (cdb, query, count, ex);
+	sqlite3_free (query);
+
+	return ret;
+}
+
+int
+camel_db_count_visible_unread_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
+{
+	int ret;
+
+	if (!cdb)
+		return -1;
+
+	char *query;
+	query = sqlite3_mprintf ("SELECT COUNT (*) FROM %Q WHERE read = 0 AND junk = 0 AND deleted = 0", table_name);
+
+	ret = camel_db_count_message_info (cdb, query, count, ex);
+	sqlite3_free (query);
+
+	return ret;
+}
+
+int
+camel_db_count_visible_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
+{
+	int ret;
+
+	if (!cdb)
+		return -1;
+
+	char *query;
+	query = sqlite3_mprintf ("SELECT COUNT (*) FROM %Q WHERE junk = 0 AND deleted = 0", table_name);
 
 	ret = camel_db_count_message_info (cdb, query, count, ex);
 	sqlite3_free (query);
@@ -238,6 +286,22 @@
 	return ret;
 }
 
+int
+camel_db_count_junk_not_deleted_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
+{
+	int ret;
+
+	if (!cdb)
+		return -1;
+
+	char *query ;
+	query = sqlite3_mprintf ("SELECT COUNT (*) FROM %Q WHERE junk = 1 AND deleted = 0", table_name);
+
+	ret = camel_db_count_message_info (cdb, query, count, ex);
+	sqlite3_free (query);
+
+	return ret;
+}
 
 int
 camel_db_count_deleted_message_info (CamelDB *cdb, const char *table_name, guint32 *count, CamelException *ex)
@@ -248,7 +312,7 @@
 		return -1;
 
 	char *query ;
-	query = sqlite3_mprintf ("SELECT COUNT (deleted) FROM %Q WHERE deleted = 1", table_name);
+	query = sqlite3_mprintf ("SELECT COUNT (*) FROM %Q WHERE deleted = 1", table_name);
 
 	ret = camel_db_count_message_info (cdb, query, count, ex);
 	sqlite3_free (query);
@@ -267,7 +331,7 @@
 	if (!cdb)
 		return -1;
 	
-	query = sqlite3_mprintf ("SELECT COUNT (uid) FROM %Q", table_name);
+	query = sqlite3_mprintf ("SELECT COUNT (*) FROM %Q", table_name);
 
 	ret = camel_db_count_message_info (cdb, query, count, ex);
 	sqlite3_free (query);
@@ -280,12 +344,17 @@
 {
   	char *errmsg;
   	//int nrecs = 0;
-	int ret;
+	int ret = -1;
 
 	if (!cdb)
 		return TRUE;
-  	ret = sqlite3_exec(cdb->db, stmt, callback, data, &errmsg);
-
+	while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED || ret == -1) {
+		 if (ret != -1)
+			  sleep (CAMEL_DB_SLEEP_INTERVAL);
+	
+		 ret = sqlite3_exec(cdb->db, stmt, callback, data, &errmsg);
+	}
+	
   	if (ret != SQLITE_OK) {
     		d(g_warning ("Error in select statement '%s' [%s].\n", stmt, errmsg));
 		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, errmsg);

Modified: branches/camel-db-summary/camel/camel-folder-search.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-search.c	(original)
+++ branches/camel-db-summary/camel/camel-folder-search.c	Thu Jun 26 10:10:04 2008
@@ -285,6 +285,7 @@
 void
 camel_folder_search_set_folder(CamelFolderSearch *search, CamelFolder *folder)
 {
+	char *tmp = camel_db_sqlize_string(folder->full_name);
 	search->folder = folder;
 
 	if (search->query)
@@ -292,7 +293,8 @@
 
 	/* FIXME: Get this string done from camel-db by parsing with sqlite_mprintf etc. */
 	search->query = g_string_new ("SELECT uid FROM ");
-	g_string_append_printf (search->query, "%s ", folder->full_name);
+	g_string_append_printf (search->query, "%s ", tmp);
+	camel_db_free_sqlized_string (tmp);
 }
 
 /**
@@ -500,7 +502,7 @@
 	printf ("\nSomething is returned in the top-level caller : [%s]\n", search->query->str);
 
 	matches = g_ptr_array_new();
-	cdb = (CamelDB *) (search->folder->parent_store->cdb);
+	cdb = (CamelDB *) (search->folder->cdb);
 	camel_db_select (cdb, search->query->str, (CamelDBSelectCB) read_uid_callback, matches, ex);
 	e_sexp_result_free(search->sexp, r);
 

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	Thu Jun 26 10:10:04 2008
@@ -477,7 +477,7 @@
 		s->flags &= ~CAMEL_SUMMARY_DIRTY;
 
 		folder_name = s->folder->full_name;
-		cdb = s->folder->parent_store->cdb;
+		cdb = s->folder->cdb;
 		
 		CAMEL_SUMMARY_UNLOCK(s, ref_lock);
 		CAMEL_SUMMARY_UNLOCK(s, summary_lock);
@@ -717,7 +717,7 @@
 	d(printf ("\ncamel_folder_summary_reload_from_db called \n"));
 
 	folder_name = s->folder->full_name;
-	cdb = s->folder->parent_store->cdb;
+	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);
@@ -742,7 +742,7 @@
 		return ret;
 
 	folder_name = s->folder->full_name;
-	cdb = s->folder->parent_store->cdb;
+	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);
@@ -1025,7 +1025,7 @@
 	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)value;	
 	CamelFolderSummary *s = (CamelFolderSummary *)mi->summary;
 	char *folder_name = s->folder->full_name;
-	CamelDB *cdb = s->folder->parent_store->cdb;
+	CamelDB *cdb = s->folder->cdb;
 	CamelMIRecord *mir;
 
 	if (!mi->dirty)
@@ -1056,7 +1056,7 @@
 static int
 save_message_infos_to_db (CamelFolderSummary *s, CamelException *ex)
 {
-	CamelDB *cdb = s->folder->parent_store->cdb;
+	CamelDB *cdb = s->folder->cdb;
 	char *folder_name;
 
 	folder_name = s->folder->full_name;
@@ -1075,7 +1075,7 @@
 int
 camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex)
 {
-	CamelDB *cdb = s->folder->parent_store->cdb;
+	CamelDB *cdb = s->folder->cdb;
 	CamelFIRecord *record;
 	int ret;
 
@@ -1736,7 +1736,7 @@
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
 
 	folder_name = s->folder->full_name;
-	cdb = s->folder->parent_store->cdb;
+	cdb = s->folder->cdb;
 
 	CAMEL_SUMMARY_LOCK(s, summary_lock);
 	if (camel_folder_summary_count(s) == 0) {
@@ -1769,7 +1769,7 @@
 	camel_exception_init (&ex);
 
 	folder_name = s->folder->full_name;
-	cdb = s->folder->parent_store->cdb;
+	cdb = s->folder->cdb;
 
 	if (camel_db_delete_uid (cdb, folder_name, uid, &ex) != 0)
 		return ;
@@ -1926,7 +1926,7 @@
 		camel_exception_init (&ex);
 
 		folder_name = s->folder->full_name;
-		cdb = s->folder->parent_store->cdb;
+		cdb = s->folder->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);
@@ -2229,7 +2229,7 @@
 	CamelFIRecord * record = g_new0 (CamelFIRecord, 1);
 	CamelDB *db;
 
-	db = s->folder->parent_store->cdb;
+	db = s->folder->cdb;
 	//char *table_name = safe_table (camel_file_util_safe_filename (s->folder->full_name));
 	char *table_name = s->folder->full_name;
 

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	Thu Jun 26 10:10:04 2008
@@ -199,6 +199,11 @@
 		camel_object_unref (camel_folder->summary);
 
 	camel_folder_change_info_free(p->changed_frozen);
+
+	if (camel_folder->cdb) {
+		camel_db_close (camel_folder->cdb);
+		camel_folder->cdb = NULL;
+	}
 	
 	g_static_rec_mutex_free(&p->lock);
 	g_static_mutex_free(&p->change_lock);
@@ -238,6 +243,10 @@
 camel_folder_construct (CamelFolder *folder, CamelStore *parent_store,
 			const char *full_name, const char *name)
 {
+	char *store_db_path;
+	CamelService *service = (CamelService *) parent_store;
+	CamelException ex;
+	
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 	g_return_if_fail (CAMEL_IS_STORE (parent_store));
 	g_return_if_fail (folder->parent_store == NULL);
@@ -249,6 +258,23 @@
 
 	folder->name = g_strdup (name);
 	folder->full_name = g_strdup (full_name);
+
+	store_db_path = g_build_filename (service->url->path, CAMEL_DB_FILE, NULL);
+	camel_exception_init(&ex);
+	if (strlen (store_db_path) < 2) {
+		g_free (store_db_path);
+		store_db_path = g_build_filename ( camel_session_get_storage_path ((CamelSession *)camel_service_get_session (service), service, &ex), CAMEL_DB_FILE, NULL);		
+	}
+
+
+	folder->cdb = camel_db_open (store_db_path, &ex);
+	g_free (store_db_path);
+	
+	if (camel_exception_is_set (&ex)) {
+		g_print ("Exiting without success for stire_db_path : [%s]: %s\n", store_db_path, camel_exception_get_description(&ex));
+		camel_exception_clear(&ex);
+		return;
+	}	
 }
 
 
@@ -352,9 +378,14 @@
 				int j;
 				CamelMessageInfo *info;
 
-				#warning "Make direct calls to DB"
 				/* TODO: Locking? */
-				unread = 0;
+				#warning "unread should be unread and not del/junk and take care of dirty infos also"
+				camel_db_count_visible_unread_message_info (folder->cdb, folder->full_name, &unread, ex);
+				camel_db_count_junk_message_info (folder->cdb, folder->full_name, &junked, ex);
+				camel_db_count_deleted_message_info (folder->cdb, folder->full_name, &deleted, ex);
+				camel_db_count_junk_not_deleted_message_info (folder->cdb, folder->full_name, &junked_not_deleted, ex);
+				camel_db_count_visible_message_info (folder->cdb, folder->full_name, &visible, ex);
+#if 0				
 				count = camel_folder_summary_count (folder->summary);
 				for (j = 0; j < count; j++) {
 					if ((info = camel_folder_summary_index (folder->summary, j))) {
@@ -374,7 +405,7 @@
 						camel_message_info_free(info);
 					}
 				}
-
+#endif
 				#warning "I added it for vfolders summary storage, does it harm ?"
 				folder->summary->junk_count = junked;
 				folder->summary->deleted_count = deleted;

Modified: branches/camel-db-summary/camel/camel-folder.h
==============================================================================
--- branches/camel-db-summary/camel/camel-folder.h	(original)
+++ branches/camel-db-summary/camel/camel-folder.h	Thu Jun 26 10:10:04 2008
@@ -109,6 +109,7 @@
 
 	guint32 folder_flags;
 	guint32 permanent_flags;
+	CamelDB *cdb;
 };
 
 #define CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY (1<<0)

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	Thu Jun 26 10:10:04 2008
@@ -256,7 +256,7 @@
 
         #warning "fix exceptions and note return values"
 	#warning "if Evo's junk/trash vfolders make it VJunk VTrash instead of .#evolution/Junk-or-whatever"		
-	camel_db_create_vfolder (parent->parent_store->cdb, parent->full_name, NULL);
+	camel_db_create_vfolder (parent->cdb, parent->full_name, NULL);
 
 	#warning "handle excep and ret"
 	camel_folder_summary_header_load_from_db ((CamelFolderSummary *)s, parent->parent_store, parent->full_name, NULL);	
@@ -271,7 +271,7 @@
 	GPtrArray *array;
 
 	#warning "fix exception passing"
-	array = camel_db_get_vuids_from_vfolder(cfs->folder->parent_store->cdb, cfs->folder->full_name, shash, NULL);
+	array = camel_db_get_vuids_from_vfolder(cfs->folder->cdb, cfs->folder->full_name, shash, NULL);
 	
 	g_free(shash);
 

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	Thu Jun 26 10:10:04 2008
@@ -1004,7 +1004,7 @@
 		int dcount =0;
 
 	
-		if (camel_db_count_deleted_message_info (s->folder->parent_store->cdb, s->folder->full_name, &dcount, ex) == -1)
+		if (camel_db_count_deleted_message_info (s->folder->cdb, s->folder->full_name, &dcount, ex) == -1)
 			return -1;
 		if (dcount)
 			quick = FALSE;



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