From: Pierre-Luc Beaudoin Date: Sat, 2 May 2009 00:13:11 +0000 (-0400) Subject: Substract the highest removed popularity from non cleared tiles X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7be98e9dabe11362e86192f63116a1b7f76a2d73;p=libchamplain Substract the highest removed popularity from non cleared tiles Without this the tiles that didn't get deleted have a big head start on the popularity side on new tiles. --- diff --git a/champlain/champlain-cache.c b/champlain/champlain-cache.c index 221fc21..47b30b5 100644 --- a/champlain/champlain-cache.c +++ b/champlain/champlain-cache.c @@ -473,6 +473,8 @@ champlain_cache_purge (ChamplainCache *self) sqlite3_stmt *stmt; int rc = 0; guint current_size = 0; + guint highest_popularity = 0; + gchar *error; query = g_strdup_printf ("SELECT SUM (size) FROM tiles;"); rc = sqlite3_prepare (priv->data, query, strlen (query), &stmt, NULL); @@ -494,7 +496,7 @@ champlain_cache_purge (ChamplainCache *self) sqlite3_finalize (stmt); /* Ok, delete the less popular tiles until size_limit reached */ - query = g_strdup_printf ("SELECT filename, size FROM tiles ORDER BY popularity;"); + query = g_strdup_printf ("SELECT filename, size, popularity FROM tiles ORDER BY popularity;"); rc = sqlite3_prepare (priv->data, query, strlen (query), &stmt, NULL); if (rc != SQLITE_OK) { @@ -509,6 +511,7 @@ champlain_cache_purge (ChamplainCache *self) filename = sqlite3_column_text (stmt, 0); size = sqlite3_column_int (stmt, 1); + highest_popularity = sqlite3_column_int (stmt, 2); DEBUG ("Deleting %s of size %d", filename, size); delete_tile (self, filename); @@ -521,5 +524,15 @@ champlain_cache_purge (ChamplainCache *self) sqlite3_finalize (stmt); g_free (query); + + query = g_strdup_printf ("UPDATE tiles SET popularity = popularity - %d;", + highest_popularity); + sqlite3_exec (priv->data, query, NULL, NULL, &error); + if (error != NULL) + { + DEBUG ("Updating popularity failed: %s", error); + sqlite3_free (error); + } + g_free (query); }