[evolution-patches] [GW-Mailer] Get Multiple Items in a single call



Hi,

Attached patch is to get multiple items together instead of getting
one-by-one so that the operations complete faster.

Please review.

Sankar

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/ChangeLog,v
retrieving revision 1.156
diff -u -p -r1.156 ChangeLog
--- ChangeLog	18 Apr 2006 15:15:30 -0000	1.156
+++ ChangeLog	19 Apr 2006 07:08:11 -0000
@@ -1,3 +1,8 @@
+2006-04-19  Sankar P  <psankar novell com>
+
+	* camel-groupwise-folder.c:
+	Get Items in a bulk instead of one-by-one.
+
 2006-04-18  Sankar P  <psankar novell com>
 
 	* camel-groupwise-folder.c: (groupwise_sync):
Index: camel-groupwise-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/camel-groupwise-folder.c,v
retrieving revision 1.130
diff -u -p -r1.130 camel-groupwise-folder.c
--- camel-groupwise-folder.c	18 Apr 2006 15:15:30 -0000	1.130
+++ camel-groupwise-folder.c	19 Apr 2006 07:08:12 -0000
@@ -586,7 +586,7 @@ groupwise_sync (CamelFolder *folder, gbo
 	EGwConnectionStatus status;
 	EGwConnection *cnc;
 	int count, i;
-		
+
 	if (((CamelOfflineStore *) gw_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL || 
 			((CamelService *)gw_store)->status == CAMEL_SERVICE_DISCONNECTED) {
 		groupwise_sync_summary (folder, ex);
@@ -893,8 +893,6 @@ groupwise_refresh_folder(CamelFolder *fo
 	struct _folder_update_msg *msg;
 	gboolean check_all = FALSE;
 
-	/* Sync-up the (un)read changes before getting updates,
-	so that the getFolderList will reflect the most recent changes too */
 	groupwise_sync (folder, FALSE, ex);
 
 	if (((CamelOfflineStore *) gw_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
@@ -1070,6 +1068,8 @@ gw_update_cache (CamelFolder *folder, GL
 	GList *item_list = list;
 	int total_items = g_list_length (item_list), i=0;
 
+	int MAX_ITERATOR_COUNT = 10;
+
 	CAMEL_SERVICE_ASSERT_LOCKED (gw_store, connect_lock);
 
 	changes = camel_folder_change_info_new ();
@@ -1084,9 +1084,14 @@ gw_update_cache (CamelFolder *folder, GL
 		is_junk = TRUE;
 	}
 
+	/*if (g_getenv ("MAX_ITERATOR_COUNT"))
+		MAX_ITERATOR_COUNT = atoi( g_getenv(MAX_ITERATOR_COUNT));
+	else
+		MAX_ITERATOR_COUNT = 1;*/
+
 	camel_operation_start (NULL, _("Fetching summary information for new messages in %s"), folder->name);
 
-	for ( ; item_list != NULL ; item_list = g_list_next (item_list) ) {
+	for ( ; item_list != NULL ; ) {
 		EGwItem *temp_item ;
 		EGwItem *item;
 		EGwItemType type = E_GW_ITEM_TYPE_UNKNOWN;
@@ -1099,187 +1104,203 @@ gw_update_cache (CamelFolder *folder, GL
 		CamelMimeMessage *mail_msg = NULL;
 		gboolean is_sent_folder = FALSE;
 
-		exists = FALSE;
-
-		if (uid_flag == FALSE) {
-			temp_item = (EGwItem *)item_list->data;
-			id = e_gw_item_get_id (temp_item);
-		} else 
-			id = (char *) item_list->data;
-
-		camel_operation_progress (NULL, (100*i)/total_items);
-
-		status = e_gw_connection_get_item (cnc, container_id, id, "peek default distribution recipient message attachments subject notification created recipientStatus status size", &item);
-		if (status != E_GW_CONNECTION_STATUS_OK) {
-			i++;
-			continue;
-		}
-
-		/************************ First populate summary *************************/
-		mi = NULL;
-		pmi = NULL;
-		pmi = camel_folder_summary_uid (folder->summary, id);
-		if (pmi) {
-			exists = TRUE;
-			camel_message_info_ref (pmi);
-			mi = (CamelGroupwiseMessageInfo *)pmi;
+		GPtrArray *items_iterator = NULL;
+		int iterator_count;
+		GList *items_list;
+
+		items_list = NULL;
+
+		for (iterator_count = 0; iterator_count < MAX_ITERATOR_COUNT && item_list != NULL ; iterator_count++) {
+			if (!items_iterator)
+				items_iterator = g_ptr_array_new ();
+			if (uid_flag == FALSE) {
+				temp_item = (EGwItem *)item_list->data;
+				g_ptr_array_add (items_iterator, (char *)e_gw_item_get_id (temp_item));
+			} else 
+				g_ptr_array_add (items_iterator, (char *) item_list->data);
+			item_list = g_list_next (item_list);
 		}
 
-		if (!exists) {
-			type = e_gw_item_get_item_type (item);
-			if ((type == E_GW_ITEM_TYPE_CONTACT) || (type == E_GW_ITEM_TYPE_UNKNOWN)) {
-				exists = FALSE;
+		camel_operation_progress (NULL, (100*i)/total_items);
+		if (items_iterator) {
+			status = e_gw_connection_get_items_from_ids (cnc, container_id, "peek default distribution recipient message attachments subject notification created recipientStatus status size", items_iterator, &items_list);
+			if (status != E_GW_CONNECTION_STATUS_OK) 
 				continue;
-			}
-
-			mi = (CamelGroupwiseMessageInfo *)camel_message_info_new (folder->summary); 
-			if (mi->info.content == NULL) {
-				mi->info.content = camel_folder_summary_content_info_new (folder->summary);
-				mi->info.content->type = camel_content_type_new ("multipart", "mixed");
-			}
-		}
-
-		/*all items in the Junk Mail folder should have this flag set*/
-		if (is_junk)
-			mi->info.flags |= CAMEL_GW_MESSAGE_JUNK;
 
-		item_status = e_gw_item_get_item_status (item);
-		if (item_status & E_GW_ITEM_STAT_READ)
-			status_flags |= CAMEL_MESSAGE_SEEN;
-		else 
-			mi->info.flags &= ~CAMEL_MESSAGE_SEEN;
+			while (items_list) {
+				item = (EGwItem *) items_list->data;
+				items_list = g_list_next (items_list);
+				exists = FALSE;
 
-		if (item_status & E_GW_ITEM_STAT_REPLIED)
-			status_flags |= CAMEL_MESSAGE_ANSWERED;
-		if (exists) 
-			mi->info.flags |= status_flags;
-		else 
-			mi->info.flags = status_flags;
+				/************************ First populate summary *************************/
+				mi = NULL;
+				pmi = NULL;
+				pmi = camel_folder_summary_uid (folder->summary, id);
+				if (pmi) {
+					exists = TRUE;
+					camel_message_info_ref (pmi);
+					mi = (CamelGroupwiseMessageInfo *)pmi;
+				}
 
-		priority = e_gw_item_get_priority (item);
-		if (priority && !(g_ascii_strcasecmp (priority,"High"))) {
-			mi->info.flags |= CAMEL_MESSAGE_FLAGGED;
-		}
+				if (!exists) {
+					type = e_gw_item_get_item_type (item);
+					if ((type == E_GW_ITEM_TYPE_CONTACT) || (type == E_GW_ITEM_TYPE_UNKNOWN)) {
+						exists = FALSE;
+						continue;
+					}
 
-		mi->server_flags = mi->info.flags;
+					mi = (CamelGroupwiseMessageInfo *)camel_message_info_new (folder->summary); 
+					if (mi->info.content == NULL) {
+						mi->info.content = camel_folder_summary_content_info_new (folder->summary);
+						mi->info.content->type = camel_content_type_new ("multipart", "mixed");
+					}
+				}
 
-		attach_list = e_gw_item_get_attach_id_list (item);
-		if (attach_list)  {
-			GSList *al = attach_list;
-			gboolean has_attachments = TRUE;
-			EGwItemAttachment *attach = (EGwItemAttachment *)al->data;
+				/*all items in the Junk Mail folder should have this flag set*/
+				if (is_junk)
+					mi->info.flags |= CAMEL_GW_MESSAGE_JUNK;
+
+				item_status = e_gw_item_get_item_status (item);
+				if (item_status & E_GW_ITEM_STAT_READ)
+					status_flags |= CAMEL_MESSAGE_SEEN;
+				else 
+					mi->info.flags &= ~CAMEL_MESSAGE_SEEN;
+
+				if (item_status & E_GW_ITEM_STAT_REPLIED)
+					status_flags |= CAMEL_MESSAGE_ANSWERED;
+				if (exists) 
+					mi->info.flags |= status_flags;
+				else 
+					mi->info.flags = status_flags;
+
+				priority = e_gw_item_get_priority (item);
+				if (priority && !(g_ascii_strcasecmp (priority,"High"))) {
+					mi->info.flags |= CAMEL_MESSAGE_FLAGGED;
+				}
 
-			if (!g_ascii_strcasecmp (attach->name, "Mime.822") ||
-					!g_ascii_strcasecmp (attach->name, "TEXT.htm")) 
-				has_attachments = FALSE;
+				mi->server_flags = mi->info.flags;
 
-			if (has_attachments)
-				mi->info.flags |= CAMEL_MESSAGE_ATTACHMENTS;
-		}
+				attach_list = e_gw_item_get_attach_id_list (item);
+				if (attach_list)  {
+					GSList *al = attach_list;
+					gboolean has_attachments = TRUE;
+					EGwItemAttachment *attach = (EGwItemAttachment *)al->data;
+
+					if (!g_ascii_strcasecmp (attach->name, "Mime.822") ||
+							!g_ascii_strcasecmp (attach->name, "TEXT.htm")) 
+						has_attachments = FALSE;
 
-		org = e_gw_item_get_organizer (item); 
-		if (org) {
-			GString *str;
-			str = g_string_new ("");
-			if (org->display_name && org->display_name[0]) 
-				str = g_string_append (str, org->display_name);
-			if (org->email && org->email[0]) { 
-				g_string_append (str, "<");
-				str = g_string_append (str, org->email);
-				g_string_append (str, ">");
-			}
-			mi->info.from = camel_pstring_strdup (str->str);
-			g_string_free (str, TRUE);
-		}
-		g_string_truncate (str, 0);
-		recp_list = e_gw_item_get_recipient_list (item);
-		if (recp_list) {
-			GSList *rl;
-			int i = 0;
-			for (rl = recp_list; rl != NULL; rl = rl->next) {
-				EGwItemRecipient *recp = (EGwItemRecipient *) rl->data;
-				if (recp->type == E_GW_ITEM_RECIPIENT_TO) {
-					if (i)
-						str = g_string_append (str, ", ");
-					g_string_append_printf (str,"%s <%s>", recp->display_name, recp->email);
-					i++;
+					if (has_attachments)
+						mi->info.flags |= CAMEL_MESSAGE_ATTACHMENTS;
 				}
-			}
-			if (exists)
-				camel_pstring_free(mi->info.to);
-			mi->info.to = camel_pstring_strdup (str->str);
-			g_string_truncate (str, 0);
-		}
 
-		if (type == E_GW_ITEM_TYPE_APPOINTMENT
-				|| type ==  E_GW_ITEM_TYPE_NOTE 
-				|| type ==  E_GW_ITEM_TYPE_TASK ) {
-			temp_date = e_gw_item_get_start_date (item);
-			if (temp_date) {
-				time_t time = e_gw_connection_get_date_from_string (temp_date);
-				time_t actual_time = camel_header_decode_date (ctime(&time), NULL);
-				mi->info.date_sent = mi->info.date_received = actual_time;
-			}
-		} else {
-			temp_date = e_gw_item_get_delivered_date(item);
-			if (temp_date) {
-				time_t time = e_gw_connection_get_date_from_string (temp_date);
-				time_t actual_time = camel_header_decode_date (ctime(&time), NULL);
-				mi->info.date_sent = mi->info.date_received = actual_time;
-			} else {
-				time_t time;
-				time_t actual_time;
-				temp_date = e_gw_item_get_creation_date (item);
-				time = e_gw_connection_get_date_from_string (temp_date);
-				actual_time = camel_header_decode_date (ctime(&time), NULL);
-				mi->info.date_sent = mi->info.date_received = actual_time;
-			}
-		}
+				org = e_gw_item_get_organizer (item); 
+				if (org) {
+					GString *str;
+					str = g_string_new ("");
+					if (org->display_name && org->display_name[0]) 
+						str = g_string_append (str, org->display_name);
+					if (org->email && org->email[0]) { 
+						g_string_append (str, "<");
+						str = g_string_append (str, org->email);
+						g_string_append (str, ">");
+					}
+					mi->info.from = camel_pstring_strdup (str->str);
+					g_string_free (str, TRUE);
+				}
+				g_string_truncate (str, 0);
+				recp_list = e_gw_item_get_recipient_list (item);
+				if (recp_list) {
+					GSList *rl;
+					int i = 0;
+					for (rl = recp_list; rl != NULL; rl = rl->next) {
+						EGwItemRecipient *recp = (EGwItemRecipient *) rl->data;
+						if (recp->type == E_GW_ITEM_RECIPIENT_TO) {
+							if (i)
+								str = g_string_append (str, ", ");
+							g_string_append_printf (str,"%s <%s>", recp->display_name, recp->email);
+							i++;
+						}
+					}
+					if (exists)
+						camel_pstring_free(mi->info.to);
+					mi->info.to = camel_pstring_strdup (str->str);
+					g_string_truncate (str, 0);
+				}
 
-		if (!exists) {
-			mi->info.uid = g_strdup (e_gw_item_get_id(item));
-			mi->info.size = e_gw_item_get_mail_size (item);	
-			mi->info.subject = camel_pstring_strdup(e_gw_item_get_subject(item));
-		}
+				if (type == E_GW_ITEM_TYPE_APPOINTMENT
+						|| type ==  E_GW_ITEM_TYPE_NOTE 
+						|| type ==  E_GW_ITEM_TYPE_TASK ) {
+					temp_date = e_gw_item_get_start_date (item);
+					if (temp_date) {
+						time_t time = e_gw_connection_get_date_from_string (temp_date);
+						time_t actual_time = camel_header_decode_date (ctime(&time), NULL);
+						mi->info.date_sent = mi->info.date_received = actual_time;
+					}
+				} else {
+					temp_date = e_gw_item_get_delivered_date(item);
+					if (temp_date) {
+						time_t time = e_gw_connection_get_date_from_string (temp_date);
+						time_t actual_time = camel_header_decode_date (ctime(&time), NULL);
+						mi->info.date_sent = mi->info.date_received = actual_time;
+					} else {
+						time_t time;
+						time_t actual_time;
+						temp_date = e_gw_item_get_creation_date (item);
+						time = e_gw_connection_get_date_from_string (temp_date);
+						actual_time = camel_header_decode_date (ctime(&time), NULL);
+						mi->info.date_sent = mi->info.date_received = actual_time;
+					}
+				}
 
-		if (exists) {
-			camel_folder_change_info_change_uid (changes, mi->info.uid);
-			camel_message_info_free (pmi);
-		} else {
-			camel_folder_summary_add (folder->summary,(CamelMessageInfo *)mi);
-			camel_folder_change_info_add_uid (changes, mi->info.uid);
-			camel_folder_change_info_recent_uid (changes, mi->info.uid);
-		}
+				if (!exists) {
+					mi->info.uid = g_strdup (e_gw_item_get_id(item));
+					mi->info.size = e_gw_item_get_mail_size (item);	
+					mi->info.subject = camel_pstring_strdup(e_gw_item_get_subject(item));
+				}
 
-		/********************* Summary ends *************************/
-		if (!strcmp (folder->full_name, "Junk Mail"))
-			continue;
+				if (exists) {
+					camel_folder_change_info_change_uid (changes, mi->info.uid);
+					camel_message_info_free (pmi);
+				} else {
+					camel_folder_summary_add (folder->summary,(CamelMessageInfo *)mi);
+					camel_folder_change_info_add_uid (changes, mi->info.uid);
+					camel_folder_change_info_recent_uid (changes, mi->info.uid);
+				}
 
-		if (!strcmp (folder->full_name, "Sent Items"))
-			is_sent_folder = TRUE;
-		/******************** Begine Caching ************************/
-		/* add to cache if its a new message*/
-		t_cache_stream  = camel_data_cache_get (gw_folder->cache, "cache", id, ex);
-		if (t_cache_stream && !is_sent_folder) {
-			camel_object_unref (t_cache_stream);
-
-			mail_msg = groupwise_folder_item_to_msg (folder, item, ex);
-			if (mail_msg)
-				camel_medium_set_header (CAMEL_MEDIUM (mail_msg), "X-Evolution-Source", groupwise_base_url_lookup (priv));
+				/********************* Summary ends *************************/
+				if (!strcmp (folder->full_name, "Junk Mail"))
+					continue;
 
-			CAMEL_GROUPWISE_FOLDER_LOCK (folder, cache_lock);
-			if ((cache_stream = camel_data_cache_add (gw_folder->cache, "cache", id, NULL))) {
-				if (camel_data_wrapper_write_to_stream ((CamelDataWrapper *) mail_msg, 	cache_stream) == -1 || camel_stream_flush (cache_stream) == -1)
-					camel_data_cache_remove (gw_folder->cache, "cache", id, NULL);
-				camel_object_unref (cache_stream);
-			}
+				if (!strcmp (folder->full_name, "Sent Items"))
+					is_sent_folder = TRUE;
+				/******************** Begine Caching ************************/
+				/* add to cache if its a new message*/
+				t_cache_stream  = camel_data_cache_get (gw_folder->cache, "cache", id, ex);
+				if (t_cache_stream && !is_sent_folder) {
+					camel_object_unref (t_cache_stream);
+
+					mail_msg = groupwise_folder_item_to_msg (folder, item, ex);
+					if (mail_msg)
+						camel_medium_set_header (CAMEL_MEDIUM (mail_msg), "X-Evolution-Source", groupwise_base_url_lookup (priv));
+
+					CAMEL_GROUPWISE_FOLDER_LOCK (folder, cache_lock);
+					if ((cache_stream = camel_data_cache_add (gw_folder->cache, "cache", id, NULL))) {
+						if (camel_data_wrapper_write_to_stream ((CamelDataWrapper *) mail_msg, 	cache_stream) == -1 || camel_stream_flush (cache_stream) == -1)
+							camel_data_cache_remove (gw_folder->cache, "cache", id, NULL);
+						camel_object_unref (cache_stream);
+					}
 
-			camel_object_unref (mail_msg);
-			CAMEL_GROUPWISE_FOLDER_UNLOCK (folder, cache_lock);
-		}
-		/******************** Caching stuff ends *************************/
-		i++;
-	}
+					camel_object_unref (mail_msg);
+					CAMEL_GROUPWISE_FOLDER_UNLOCK (folder, cache_lock);
+				}
+				/******************** Caching stuff ends *************************/
+			} //End of While LOOP; Move onto the next item
+			g_ptr_array_free (items_iterator, FALSE);
+			items_iterator = FALSE;
+		} //End of IF for items_iterator NULL checking
+		i += MAX_ITERATOR_COUNT;
+	} // End of the FOR loop
 	camel_operation_end (NULL);
 	g_free (container_id);
 	g_string_free (str, TRUE);
@@ -1960,6 +1981,7 @@ groupwise_expunge (CamelFolder *folder, 
 	CamelFolderChangeInfo *changes;
 	int i, max;
 	gboolean delete = FALSE;
+	
 
 
 	cnc = cnc_lookup (priv);


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