evolution-data-server r8931 - branches/camel-db-summary/camel
- From: psankar svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r8931 - branches/camel-db-summary/camel
- Date: Thu, 5 Jun 2008 10:30:20 +0000 (UTC)
Author: psankar
Date: Thu Jun 5 10:30:20 2008
New Revision: 8931
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8931&view=rev
Log:
Remove msginfo with an index. DB selective UID removal etc.
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/camel-folder-summary.h
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 5 10:30:20 2008
@@ -288,7 +288,7 @@
}
int
-camel_db_delete_folder (CamelDB *cdb, char *folder, CamelException *ex)
+camel_db_delete_folder (CamelDB *cdb, const char *folder, CamelException *ex)
{
char *tab = sqlite3_mprintf ("DELETE FROM folders WHERE folder_name =%Q", folder);
int ret;
@@ -447,7 +447,7 @@
}
int
-camel_db_read_folder_info_record (CamelDB *cdb, char *folder_name, CamelFIRecord **record, CamelException *ex)
+camel_db_read_folder_info_record (CamelDB *cdb, const char *folder_name, CamelFIRecord **record, CamelException *ex)
{
char *query;
int ret;
@@ -475,7 +475,7 @@
}
int
-camel_db_read_message_info_records (CamelDB *cdb, 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;
@@ -488,7 +488,7 @@
}
int
-camel_db_delete_uid (CamelDB *cdb, char *folder, char *uid, CamelException *ex)
+camel_db_delete_uid (CamelDB *cdb, const char *folder, const char *uid, CamelException *ex)
{
char *tab = sqlite3_mprintf ("DELETE FROM %Q WHERE uid = %Q", folder, uid);
int ret;
@@ -500,27 +500,38 @@
}
int
-camel_db_delete_uids (CamelDB *cdb, char *folder, CamelException *ex, int nargs, ... )
+camel_db_delete_uids (CamelDB *cdb, const char * folder_name, GSList *uids, CamelException *ex)
{
- char *query;
- int ret, i;
- GString *str = g_string_new ("DELETE FROM %Q WHERE uid IN (");
- va_list listptr;
+ char *tmp;
+ int ret;
+ gboolean first = TRUE;
+ GString *str = g_string_new ("DELETE FROM ");
+ GSList *iterator;
+
+ tmp = sqlite3_mprintf ("%Q WHERE uid IN (", folder_name);
+ g_string_append_printf (str, "%s ", tmp);
+ sqlite3_free (tmp);
+
+ iterator = uids;
+
+ while (iterator) {
+ tmp = sqlite3_mprintf ("%Q", (char *) iterator->data);
+ iterator = iterator->next;
+
+ if (first == TRUE) {
+ g_string_append_printf (str, " %s ", tmp);
+ first = FALSE;
+ } else
+ g_string_append_printf (str, ", %s ", tmp);
- for (i = 1; i < nargs; ++i) {
- g_string_append (str, " %Q ,");
+ sqlite3_free (tmp);
}
- g_string_append (str, " %Q )" );
+ g_string_append (str, ")");
- va_start (listptr, nargs);
- query = sqlite3_vmprintf (str->str, listptr);
- va_end (listptr);
+ ret = camel_db_command (cdb, str->str, ex);
- //ret = camel_db_command (cdb, tab, ex);
-
- g_print ("The delete_uids query is : [%s]\n", query);
- sqlite3_free (query);
+ g_string_free (str, TRUE);
return 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 Thu Jun 5 10:30:20 2008
@@ -102,20 +102,21 @@
int camel_db_abort_transaction (CamelDB *cdb, CamelException *ex);
int camel_db_clear_folder_summary (CamelDB *cdb, char *folder, CamelException *ex);
-int camel_db_delete_folder (CamelDB *cdb, char *folder, CamelException *ex);
-int camel_db_delete_uid (CamelDB *cdb, char *folder, char *uid, CamelException *ex);
-int camel_db_delete_uids (CamelDB *cdb, char *folder, CamelException *ex, int nargs, ... );
+int camel_db_delete_folder (CamelDB *cdb, const char *folder, CamelException *ex);
+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_create_folders_table (CamelDB *cdb, CamelException *ex);
int camel_db_select (CamelDB *cdb, const char* stmt, CamelDBSelectCB callback, gpointer data, CamelException *ex);
int camel_db_write_folder_info_record (CamelDB *cdb, CamelFIRecord *record, CamelException *ex);
-int camel_db_read_folder_info_record (CamelDB *cdb, char *folder_name, CamelFIRecord **record, CamelException *ex);
+int camel_db_read_folder_info_record (CamelDB *cdb, const char *folder_name, CamelFIRecord **record, CamelException *ex);
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, char *folder_name, 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);
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 5 10:30:20 2008
@@ -711,7 +711,6 @@
ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer**) &s, camel_read_mir_callback, &ex);
return ret;
-
}
static int
@@ -1584,6 +1583,42 @@
CAMEL_SUMMARY_UNLOCK(s, summary_lock);
}
+/* FIXME: This is non-sense. Neither an exception is passed,
+nor a value returned. How is the caller supposed to know,
+whether the operation is succesful */
+
+void
+camel_folder_summary_clear_db (CamelFolderSummary *s)
+{
+ int i;
+ CamelDB *cdb;
+ char *folder_name;
+
+ d(printf ("\ncamel_folder_summary_load_from_db called \n"));
+ s->flags &= ~CAMEL_SUMMARY_DIRTY;
+
+ folder_name = s->folder->full_name;
+ cdb = s->folder->parent_store->cdb;
+
+ CAMEL_SUMMARY_LOCK(s, summary_lock);
+ if (camel_folder_summary_count(s) == 0) {
+ CAMEL_SUMMARY_UNLOCK(s, summary_lock);
+ return;
+ }
+
+ for (i = 0; i < s->uids->len; i++)
+ g_free (s->uids->pdata[i]);
+
+ camel_db_clear_folder_summary (cdb, folder_name, NULL);
+ g_ptr_array_set_size(s->uids, 0);
+
+ g_hash_table_destroy(s->messages_uid);
+ s->messages_uid = g_hash_table_new(g_str_hash, g_str_equal);
+
+ s->flags |= CAMEL_SUMMARY_DIRTY;
+ CAMEL_SUMMARY_UNLOCK(s, summary_lock);
+}
+
static void
summary_remove_uid (CamelFolderSummary *s, const char *uid)
{
@@ -1598,7 +1633,7 @@
folder_name = s->folder->full_name;
cdb = s->folder->parent_store->cdb;
- if (camel_db_remove_uid (cdb, folder_name, uid, &ex) != 0)
+ if (camel_db_delete_uid (cdb, folder_name, uid, &ex) != 0)
return ;
/* This could be slower, but no otherway really. FIXME: Callers have to effective and shouldn't call it recursively. */
@@ -1606,9 +1641,12 @@
if (strcmp(s->uids->pdata[i], uid) == 0) {
/* FIXME: Does using fast remove affect anything ? */
g_ptr_array_remove_index(s->messages, i);
+ break;
}
- }
+ }
+
+ return ;
}
/**
@@ -1621,8 +1659,6 @@
void
camel_folder_summary_remove (CamelFolderSummary *s, CamelMessageInfo *info)
{
- int i;
-
CAMEL_SUMMARY_LOCK(s, summary_lock);
summary_remove_uid (s, camel_message_info_uid(info));
@@ -1694,26 +1730,47 @@
* Removes an indexed range of info records.
**/
void
-camel_folder_summary_remove_range(CamelFolderSummary *s, int start, int end)
+camel_folder_summary_remove_range (CamelFolderSummary *s, int start, int end)
{
+
+ g_print ("\ncamel_folder_summary_remove_range called \n");
if (end < start)
return;
CAMEL_SUMMARY_LOCK(s, summary_lock);
+
if (start < s->uids->len) {
+
int i;
+ CamelDB *cdb;
+ CamelException ex;// May be this should come from the caller
+ char *folder_name;
+ GSList *uids = NULL;
end = MIN(end+1, s->uids->len);
- for (i=start;i<end;i++) {
- const char *uid= s->uids->pdata[i];
+ for (i = start; i < end; i++) {
+ const char *uid = s->uids->pdata[i];
+
+ uids = g_slist_prepend (uids, g_strdup (uid));
g_hash_table_remove(s->loaded_infos, uid);
}
+ camel_exception_init (&ex);
+
+ folder_name = s->folder->full_name;
+ cdb = s->folder->parent_store->cdb;
+
+ camel_db_delete_uids (cdb, folder_name, uids, &ex);
- #error "remove the list of uids from db in a optimized way"
+ g_slist_foreach (uids, (GFunc) g_free, NULL);
+ g_slist_free (uids);
+
+ /* FIXME: GOK What it means. I'll fix this later
memmove(s->messages->pdata+start, s->messages->pdata+end, (s->messages->len-end)*sizeof(s->messages->pdata[0]));
g_ptr_array_set_size(s->messages, s->messages->len - (end - start));
+ */
+
s->flags |= CAMEL_SUMMARY_DIRTY;
CAMEL_SUMMARY_UNLOCK(s, summary_lock);
Modified: branches/camel-db-summary/camel/camel-folder-summary.h
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.h (original)
+++ branches/camel-db-summary/camel/camel-folder-summary.h Thu Jun 5 10:30:20 2008
@@ -354,6 +354,7 @@
/* remove all items */
void camel_folder_summary_clear(CamelFolderSummary *summary);
+void camel_folder_summary_clear_db (CamelFolderSummary *s);
/* lookup functions */
int camel_folder_summary_count(CamelFolderSummary *summary);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]