[evolution-patches] patch for #70267 (calendar)



This patch adds 2 API calls to EFileCache to allow disabling temporarily
writing to disk, so that we can add/modify/remove a batch of objects and
do one write to disk for all changes instead of 1 per change.

It is an API change, so not sure about 2.0.x, but it should be committed
there also, I guess. Maybe we could hide the 2 API calls in the header
file?
-- 
Rodrigo Moya <rodrigo novell com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/ChangeLog,v
retrieving revision 1.188
diff -u -p -r1.188 ChangeLog
--- ChangeLog	7 Dec 2004 02:15:26 -0000	1.188
+++ ChangeLog	7 Dec 2004 13:06:13 -0000
@@ -1,3 +1,14 @@
+2004-12-07  Rodrigo Moya <rodrigo novell com>
+
+	Fixes #70267
+
+	* libedataserver/e-file-cache.[ch] (e_file_cache_freeze_changes,
+	e_file_cache_thaw_changes): new functions to disable temporarily
+	writes to disk.
+	(e_file_cache_init): initialize new private members.
+	(e_file_cache_add_object, e_file_cache_remove_object): mark the
+	cache file as dirty when we are frozen.
+
 2004-12-06  Rodney Dawes  <dobey novell com>
 
 	* Makefile.am (EXTRA_DIST): Add iconv-detect.c
Index: libedataserver/e-file-cache.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserver/e-file-cache.c,v
retrieving revision 1.11
diff -u -p -r1.11 e-file-cache.c
--- libedataserver/e-file-cache.c	22 Sep 2004 16:41:07 -0000	1.11
+++ libedataserver/e-file-cache.c	7 Dec 2004 13:06:14 -0000
@@ -29,6 +29,8 @@
 struct _EFileCachePrivate {
 	char *filename;
 	EXmlHash *xml_hash;
+	gboolean dirty;
+	gboolean frozen;
 };
 
 /* Property IDs */
@@ -148,6 +150,8 @@ e_file_cache_init (EFileCache *cache)
 	EFileCachePrivate *priv;
 
 	priv = g_new0 (EFileCachePrivate, 1);
+	priv->dirty = FALSE;
+	priv->frozen = FALSE;
 	cache->priv = priv;
 }
 
@@ -400,7 +404,12 @@ e_file_cache_add_object (EFileCache *cac
 		return FALSE;
 
 	e_xmlhash_add (priv->xml_hash, key, value);
-	e_xmlhash_write (priv->xml_hash);
+	if (priv->frozen)
+		priv->dirty = TRUE;
+	else {
+		e_xmlhash_write (priv->xml_hash);
+		priv->dirty = FALSE;
+	}
 
 	return TRUE;
 }
@@ -444,9 +453,54 @@ e_file_cache_remove_object (EFileCache *
 		return FALSE;
 
 	e_xmlhash_remove (priv->xml_hash, key);
-	e_xmlhash_write (priv->xml_hash);
+	if (priv->frozen)
+		priv->dirty = TRUE;
+	else {
+		e_xmlhash_write (priv->xml_hash);
+		priv->dirty = FALSE;
+	}
 
 	return TRUE;
+}
+
+/**
+ * e_file_cache_freeze_changes:
+ * @cache: An #EFileCache object.
+ *
+ * Disables temporarily all writes to disk for the given cache object.
+ */
+void
+e_file_cache_freeze_changes (EFileCache *cache)
+{
+	EFileCachePrivate *priv;
+
+	g_return_if_fail (E_IS_FILE_CACHE (cache));
+
+	priv = cache->priv;
+
+	priv->frozen = TRUE;
+}
+
+/**
+ * e_file_cache_thaw_changes:
+ * @cache: An #EFileCache object.
+ *
+ * Enables again writes to disk on every change.
+ */
+void
+e_file_cache_thaw_changes (EFileCache *cache)
+{
+	EFileCachePrivate *priv;
+
+	g_return_if_fail (E_IS_FILE_CACHE (cache));
+
+	priv = cache->priv;
+
+	priv->frozen = FALSE;
+	if (priv->dirty) {
+		e_xmlhash_write (priv->xml_hash);
+		priv->dirty = FALSE;
+	}
 }
 
 /**
Index: libedataserver/e-file-cache.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserver/e-file-cache.h,v
retrieving revision 1.5
diff -u -p -r1.5 e-file-cache.h
--- libedataserver/e-file-cache.h	22 Sep 2004 16:41:07 -0000	1.5
+++ libedataserver/e-file-cache.h	7 Dec 2004 13:06:14 -0000
@@ -56,6 +56,8 @@ gboolean    e_file_cache_add_object (EFi
 gboolean    e_file_cache_replace_object (EFileCache *cache, const char *key, const char *new_value);
 gboolean    e_file_cache_remove_object (EFileCache *cache, const char *key);
 
+void        e_file_cache_freeze_changes (EFileCache *cache);
+void        e_file_cache_thaw_changes (EFileCache *cache);
 const char *e_file_cache_get_filename (EFileCache *cache);
 
 G_END_DECLS
Index: calendar/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.354
diff -u -p -r1.354 ChangeLog
--- calendar/ChangeLog	6 Dec 2004 04:09:21 -0000	1.354
+++ calendar/ChangeLog	7 Dec 2004 13:06:14 -0000
@@ -1,3 +1,11 @@
+2004-12-07  Rodrigo Moya <rodrigo novell com>
+
+	Fixes #70267
+
+	* backends/groupwise/e-cal-backend-groupwise.c (get_deltas):
+	* backends/http/e-cal-backend-groupwise.c (retrieval_done): freeze
+	the cache when doing mass updates to do only one write to disk.
+
 2004-12-06  Harish Krishnaswamy <kharish novell com> 
 	* backends/groupwise/e-cal-backend-groupwise-utils.c 
 	(e_gw_connection_send_appointment) : Add correct view arguments 
Index: calendar/backends/http/e-cal-backend-http.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/backends/http/e-cal-backend-http.c,v
retrieving revision 1.20
diff -u -p -r1.20 e-cal-backend-http.c
--- calendar/backends/http/e-cal-backend-http.c	28 Sep 2004 15:58:37 -0000	1.20
+++ calendar/backends/http/e-cal-backend-http.c	7 Dec 2004 13:06:15 -0000
@@ -288,6 +288,7 @@ retrieval_done (SoupMessage *msg, ECalBa
 
 	kind = e_cal_backend_get_kind (E_CAL_BACKEND (cbhttp));
 	subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT);
+	e_file_cache_freeze_changes (E_FILE_CACHE (priv->cache));
 	while (subcomp) {
 		ECalComponent *comp;
 		icalcomponent_kind subcomp_kind;
@@ -325,6 +326,8 @@ retrieval_done (SoupMessage *msg, ECalBa
 
 		subcomp = icalcomponent_get_next_component (icalcomp, kind);
 	}
+
+	e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
 
 	/* notify the removals */
 	g_hash_table_foreach_remove (old_cache, (GHRFunc) notify_and_remove_from_cache, cbhttp);
Index: calendar/backends/groupwise/e-cal-backend-groupwise.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/backends/groupwise/e-cal-backend-groupwise.c,v
retrieving revision 1.106
diff -u -p -r1.106 e-cal-backend-groupwise.c
--- calendar/backends/groupwise/e-cal-backend-groupwise.c	2 Dec 2004 13:19:00 -0000	1.106
+++ calendar/backends/groupwise/e-cal-backend-groupwise.c	7 Dec 2004 13:06:15 -0000
@@ -225,6 +225,8 @@ get_deltas (gpointer handle)
 		e_cal_backend_groupwise_notify_error_code (cbgw, status);
 		return TRUE;
 	}
+
+	e_file_cache_freeze_changes (E_FILE_CACHE (cache));
 	for (; item_list != NULL; item_list = g_slist_next(item_list)) {
 		EGwItem *item = E_GW_ITEM(item_list->data);
 		ECalComponent *comp = e_gw_item_to_cal_component (item, cbgw);
@@ -250,13 +252,16 @@ get_deltas (gpointer handle)
 		g_slist_free (item_list);
 		item_list = NULL;
 	}
+	e_file_cache_thaw_changes (E_FILE_CACHE (cache));
+
 	status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id,"recipients message recipientStatus  default", time_string, "Modified", "CalendarItem", NULL,  -1,  &item_list);
 	
 	if (status != E_GW_CONNECTION_STATUS_OK) {
 		e_cal_backend_groupwise_notify_error_code (cbgw, status);
 		return TRUE;
 	}
-	
+
+	e_file_cache_freeze_changes (E_FILE_CACHE (cache));
 	for (; item_list != NULL; item_list = g_slist_next(item_list)) {
 		EGwItem *item = E_GW_ITEM(item_list->data);
 		ECalComponent *modified_comp, *cache_comp;
@@ -279,6 +284,8 @@ get_deltas (gpointer handle)
 		g_object_unref (item);
 		g_object_unref (modified_comp);
 	}
+	e_file_cache_thaw_changes (E_FILE_CACHE (cache));
+
 	if (item_list) {
 		g_slist_free (item_list);
 		item_list = NULL;
@@ -301,7 +308,8 @@ get_deltas (gpointer handle)
 				g_slist_find_custom (cache_keys, l->data, (GCompareFunc) strcmp));
 		g_free (l->data);
 	}
-	
+
+	e_file_cache_freeze_changes (E_FILE_CACHE (cache));
 	for (l = cache_keys; l ; l = g_slist_next (l)) {
 		/* assumes rid is null - which works for now */
 		ECalComponent *comp = NULL;
@@ -319,6 +327,8 @@ get_deltas (gpointer handle)
 		}
 		g_object_unref (comp);
 	}
+	e_file_cache_thaw_changes (E_FILE_CACHE (cache));
+
 	if (item_list) {
 		g_slist_free (item_list);
 		item_list = NULL;


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