aboutsummaryrefslogtreecommitdiff
path: root/src/application-service-lru-file.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-01-20 16:41:38 -0600
committerTed Gould <ted@gould.cx>2010-01-20 16:41:38 -0600
commitda6242ba497bf70eb2ee8c75e74ddf5ac7f699ca (patch)
treeb3eac4e0140706123a6d620521762a965b2802b2 /src/application-service-lru-file.c
parent0ccf950d37c2de390f79c10d9bebbd4ca6dfc894 (diff)
downloadayatana-indicator-application-da6242ba497bf70eb2ee8c75e74ddf5ac7f699ca.tar.gz
ayatana-indicator-application-da6242ba497bf70eb2ee8c75e74ddf5ac7f699ca.tar.bz2
ayatana-indicator-application-da6242ba497bf70eb2ee8c75e74ddf5ac7f699ca.zip
Looking at the last touch date of entries as we're loading the file and removing ones that are very old.
Diffstat (limited to 'src/application-service-lru-file.c')
-rw-r--r--src/application-service-lru-file.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/application-service-lru-file.c b/src/application-service-lru-file.c
index fec9644..c69a20f 100644
--- a/src/application-service-lru-file.c
+++ b/src/application-service-lru-file.c
@@ -60,6 +60,7 @@ static void app_lru_file_init (AppLruFile *self);
static void app_lru_file_dispose (GObject *object);
static void app_lru_file_finalize (GObject *object);
static void app_data_free (gpointer data);
+static void get_dirty (AppLruFile * lrufile);
static gboolean load_from_file (gpointer data);
static void load_file_object_cb (JsonObject * obj, const gchar * key, JsonNode * value, gpointer data);
static void clean_off_hash_cb (gpointer key, gpointer value, gpointer data);
@@ -183,7 +184,7 @@ load_from_file (gpointer data)
return FALSE;
}
- json_object_foreach_member(rootobj, load_file_object_cb, priv);
+ json_object_foreach_member(rootobj, load_file_object_cb, lrufile);
g_object_unref(parser);
return FALSE;
@@ -195,7 +196,8 @@ load_from_file (gpointer data)
static void
load_file_object_cb (JsonObject * rootobj, const gchar * key, JsonNode * value, gpointer data)
{
- AppLruFilePrivate * priv = (AppLruFilePrivate *)data;
+ AppLruFile * lrufile = (AppLruFile *)data;
+ AppLruFilePrivate * priv = APP_LRU_FILE_GET_PRIVATE(lrufile);
/* We're not looking at this today. */
if (!g_strcmp0(key, ENTRY_VERSION)) {
@@ -214,9 +216,35 @@ load_file_object_cb (JsonObject * rootobj, const gchar * key, JsonNode * value,
if (obj_category == NULL || obj_first == NULL || obj_last == NULL) {
g_warning("Node '%s' is missing data. Got: ('%s', '%s', '%s')", key, obj_category, obj_first, obj_last);
+ get_dirty(lrufile);
+ return;
+ }
+
+ /* Check to see how old this entry is. If it hasn't been
+ used in the last year, we remove the cruft. */
+ GTimeVal currenttime;
+ g_get_current_time(&currenttime);
+ GDate * currentdate = g_date_new();
+ g_date_set_time_val(currentdate, &currenttime);
+
+ GTimeVal lasttouch;
+ g_time_val_from_iso8601(obj_last, &lasttouch);
+ GDate * lastdate = g_date_new();
+ g_date_set_time_val(lastdate, &lasttouch);
+
+ gint spread = g_date_days_between(lastdate, currentdate);
+
+ g_date_free(currentdate);
+ g_date_free(lastdate);
+
+ if (spread > 365) {
+ g_debug("Removing node '%s' as it's %d days old.", key, spread);
+ get_dirty(lrufile);
return;
}
+ /* See if we already have one of these. It's a little bit
+ unlikely, but since we're async, we need to check */
gpointer datapntr = g_hash_table_lookup(priv->apps, key);
if (datapntr == NULL) {
/* Build a new node */