event: Remove event cache
It's for the best. The cache was being more problematic than it was worth it.
This commit is contained in:
+7
-104
@@ -134,40 +134,6 @@ enum {
|
|||||||
|
|
||||||
static GParamSpec* properties[N_PROPS] = { NULL, };
|
static GParamSpec* properties[N_PROPS] = { NULL, };
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GcalEvent cache
|
|
||||||
*/
|
|
||||||
|
|
||||||
G_LOCK_DEFINE (main_lock);
|
|
||||||
G_LOCK_DEFINE (event_cache_lock);
|
|
||||||
|
|
||||||
static GHashTable *event_cache = NULL;
|
|
||||||
|
|
||||||
G_DEFINE_CONSTRUCTOR (init_event_cache_map);
|
|
||||||
|
|
||||||
static void
|
|
||||||
init_event_cache_map (void)
|
|
||||||
{
|
|
||||||
event_cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_DEFINE_DESTRUCTOR (destroy_event_cache_map);
|
|
||||||
|
|
||||||
static void
|
|
||||||
destroy_event_cache_map (void)
|
|
||||||
{
|
|
||||||
GList *events;
|
|
||||||
|
|
||||||
g_debug ("Number of cached events at destruction: %d", g_hash_table_size (event_cache));
|
|
||||||
|
|
||||||
/* Destroy all events */
|
|
||||||
events = g_hash_table_get_values (event_cache);
|
|
||||||
g_list_free_full (events, g_object_unref);
|
|
||||||
|
|
||||||
g_hash_table_destroy (event_cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Auxiliary methods
|
* Auxiliary methods
|
||||||
*/
|
*/
|
||||||
@@ -267,23 +233,11 @@ gcal_event_update_uid_internal (GcalEvent *self)
|
|||||||
{
|
{
|
||||||
ECalComponentId *id;
|
ECalComponentId *id;
|
||||||
const gchar *source_id;
|
const gchar *source_id;
|
||||||
gboolean should_update_cache;
|
|
||||||
|
|
||||||
/* Setup event uid */
|
/* Setup event uid */
|
||||||
source_id = self->calendar ? gcal_calendar_get_id (self->calendar) : "";
|
source_id = self->calendar ? gcal_calendar_get_id (self->calendar) : "";
|
||||||
id = e_cal_component_get_id (self->component);
|
id = e_cal_component_get_id (self->component);
|
||||||
|
|
||||||
should_update_cache = self->uid != NULL;
|
|
||||||
|
|
||||||
G_LOCK (event_cache_lock);
|
|
||||||
|
|
||||||
if (should_update_cache)
|
|
||||||
{
|
|
||||||
g_debug ("Removing '%s' (%p) from cache", self->uid, self);
|
|
||||||
g_hash_table_remove (event_cache, self->uid);
|
|
||||||
g_clear_pointer (&self->uid, g_free);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e_cal_component_id_get_rid (id) != NULL)
|
if (e_cal_component_id_get_rid (id) != NULL)
|
||||||
{
|
{
|
||||||
self->uid = g_strdup_printf ("%s:%s:%s",
|
self->uid = g_strdup_printf ("%s:%s:%s",
|
||||||
@@ -298,14 +252,6 @@ gcal_event_update_uid_internal (GcalEvent *self)
|
|||||||
e_cal_component_id_get_uid (id));
|
e_cal_component_id_get_uid (id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (should_update_cache)
|
|
||||||
{
|
|
||||||
g_debug ("Adding %s to the cache", self->uid);
|
|
||||||
g_hash_table_insert (event_cache, self->uid, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_UNLOCK (event_cache_lock);
|
|
||||||
|
|
||||||
e_cal_component_id_free (id);
|
e_cal_component_id_free (id);
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_UID]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_UID]);
|
||||||
}
|
}
|
||||||
@@ -343,19 +289,21 @@ static void
|
|||||||
gcal_event_set_component_internal (GcalEvent *self,
|
gcal_event_set_component_internal (GcalEvent *self,
|
||||||
ECalComponent *component)
|
ECalComponent *component)
|
||||||
{
|
{
|
||||||
if (g_set_object (&self->component, component))
|
g_autoptr (GTimeZone) zone_start = NULL;
|
||||||
{
|
g_autoptr (GTimeZone) zone_end = NULL;
|
||||||
ECalComponentDateTime *start;
|
ECalComponentDateTime *start;
|
||||||
ECalComponentDateTime *end;
|
ECalComponentDateTime *end;
|
||||||
ECalComponentText *text;
|
ECalComponentText *text;
|
||||||
ICalTime *date;
|
ICalTime *date;
|
||||||
GDateTime *date_start;
|
GDateTime *date_start;
|
||||||
GTimeZone *zone_start = NULL;
|
|
||||||
GDateTime *date_end;
|
GDateTime *date_end;
|
||||||
GTimeZone *zone_end = NULL;
|
|
||||||
gboolean start_is_all_day, end_is_all_day;
|
gboolean start_is_all_day, end_is_all_day;
|
||||||
gchar *description, *location;
|
gchar *description, *location;
|
||||||
|
|
||||||
|
g_assert (self->component == NULL);
|
||||||
|
|
||||||
|
self->component = e_cal_component_clone (component);
|
||||||
|
|
||||||
/* Setup start date */
|
/* Setup start date */
|
||||||
start = e_cal_component_get_dtstart (component);
|
start = e_cal_component_get_dtstart (component);
|
||||||
|
|
||||||
@@ -453,8 +401,6 @@ gcal_event_set_component_internal (GcalEvent *self,
|
|||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RECURRENCE]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RECURRENCE]);
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPONENT]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPONENT]);
|
||||||
|
|
||||||
g_clear_pointer (&zone_start, g_time_zone_unref);
|
|
||||||
g_clear_pointer (&zone_end, g_time_zone_unref);
|
|
||||||
g_clear_pointer (&description, g_free);
|
g_clear_pointer (&description, g_free);
|
||||||
g_clear_pointer (&location, g_free);
|
g_clear_pointer (&location, g_free);
|
||||||
|
|
||||||
@@ -462,7 +408,6 @@ gcal_event_set_component_internal (GcalEvent *self,
|
|||||||
e_cal_component_datetime_free (start);
|
e_cal_component_datetime_free (start);
|
||||||
e_cal_component_datetime_free (end);
|
e_cal_component_datetime_free (end);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GInitable iface implementation
|
* GInitable iface implementation
|
||||||
@@ -500,12 +445,6 @@ gcal_event_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
GcalEvent *self = (GcalEvent *)object;
|
GcalEvent *self = (GcalEvent *)object;
|
||||||
|
|
||||||
g_debug ("Removing '%s' (%p) from cache", self->uid, self);
|
|
||||||
|
|
||||||
G_LOCK (event_cache_lock);
|
|
||||||
g_hash_table_remove (event_cache, self->uid);
|
|
||||||
G_UNLOCK (event_cache_lock);
|
|
||||||
|
|
||||||
g_clear_pointer (&self->dt_start, g_date_time_unref);
|
g_clear_pointer (&self->dt_start, g_date_time_unref);
|
||||||
g_clear_pointer (&self->dt_end, g_date_time_unref);
|
g_clear_pointer (&self->dt_end, g_date_time_unref);
|
||||||
g_clear_pointer (&self->summary, g_free);
|
g_clear_pointer (&self->summary, g_free);
|
||||||
@@ -827,48 +766,12 @@ gcal_event_new (GcalCalendar *calendar,
|
|||||||
ECalComponent *component,
|
ECalComponent *component,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GcalEvent *event;
|
return g_initable_new (GCAL_TYPE_EVENT,
|
||||||
g_autofree gchar *uuid;
|
|
||||||
gboolean event_cached;
|
|
||||||
|
|
||||||
G_LOCK (main_lock);
|
|
||||||
|
|
||||||
uuid = get_uuid_from_component (gcal_calendar_get_source (calendar), component);
|
|
||||||
|
|
||||||
G_LOCK (event_cache_lock);
|
|
||||||
event_cached = g_hash_table_contains (event_cache, uuid);
|
|
||||||
G_UNLOCK (event_cache_lock);
|
|
||||||
|
|
||||||
if (event_cached)
|
|
||||||
{
|
|
||||||
g_debug ("Using cached value for %s", uuid);
|
|
||||||
|
|
||||||
event = g_hash_table_lookup (event_cache, uuid);
|
|
||||||
gcal_event_set_component_internal (event, component);
|
|
||||||
g_object_ref (event);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
event = g_initable_new (GCAL_TYPE_EVENT,
|
|
||||||
NULL,
|
NULL,
|
||||||
error,
|
error,
|
||||||
"calendar", calendar,
|
"calendar", calendar,
|
||||||
"component", component,
|
"component", component,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (event)
|
|
||||||
{
|
|
||||||
g_debug ("Adding %s to the cache", event->uid);
|
|
||||||
|
|
||||||
G_LOCK (event_cache_lock);
|
|
||||||
g_hash_table_insert (event_cache, event->uid, event);
|
|
||||||
G_UNLOCK (event_cache_lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
G_UNLOCK (main_lock);
|
|
||||||
|
|
||||||
return event;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user