From: Pierre-Luc Beaudoin Date: Sat, 17 Oct 2009 15:37:13 +0000 (-0400) Subject: Increase performance of sqlite to lower IO wait X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=954e21eb558a33649d68a378995417a3b0a63e8d;p=libchamplain Increase performance of sqlite to lower IO wait This could corrupt database if many libchamplain apps are running at the same time, but the performance gain is worth more. Plus this information is not vital. --- diff --git a/champlain/champlain-cache.c b/champlain/champlain-cache.c index 8c9e5ba..8c08d07 100644 --- a/champlain/champlain-cache.c +++ b/champlain/champlain-cache.c @@ -237,16 +237,28 @@ champlain_cache_init (ChamplainCache *self) goto cleanup; } + sqlite3_exec (priv->data, + "PRAGMA synchronous=OFF;" + "PRAGMA count_changes=OFF;", + NULL, NULL, &error_msg); + if (error_msg != NULL) + { + DEBUG ("Set PRAGMA: %s", error_msg); + sqlite3_free (error_msg); + goto cleanup; + } + sqlite3_exec (priv->data, "CREATE TABLE IF NOT EXISTS tiles (" - "filename TEXT PRIMARY KEY, etag TEXT, " + "filename TEXT PRIMARY KEY, " + "etag TEXT, " "popularity INT DEFAULT 1, " "size INT DEFAULT 0)", NULL, NULL, &error_msg); if (error_msg != NULL) { DEBUG ("Creating table 'tiles' failed: %s", error_msg); - sqlite3_free (error_msg); + sqlite3_free (error_msg); goto cleanup; } @@ -362,6 +374,7 @@ champlain_cache_fill_tile (ChamplainCache *self, ChamplainCachePrivate *priv = GET_PRIVATE (self); filename = champlain_tile_get_filename (tile); + DEBUG ("fill of %s", filename); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) goto cleanup; @@ -460,6 +473,8 @@ champlain_cache_tile_is_expired (ChamplainCache *self, g_time_val_add (&now, (-24ul * 60ul * 60ul * 1000ul * 1000ul * 7ul)); // Cache expires 7 days validate_cache = modified_time->tv_sec < now.tv_sec; + DEBUG ("%p is %s expired", tile, (validate_cache ? "": "not")); + return validate_cache; } @@ -481,6 +496,8 @@ inc_popularity (gpointer data) last = g_slist_last (priv->popularity_queue); filename = last->data; + DEBUG ("popularity of %s", filename); + sql_rc = sqlite3_bind_text (priv->stmt_update, 1, filename, -1, SQLITE_STATIC); if (sql_rc != SQLITE_OK) { @@ -504,7 +521,7 @@ cleanup: g_free (filename); /* Ask to be called again until the list is emptied */ - return TRUE; + return priv->popularity_queue != NULL; } static void @@ -560,6 +577,8 @@ champlain_cache_update_tile (ChamplainCache *self, ChamplainCachePrivate *priv = GET_PRIVATE (self); + DEBUG ("Update of %p", tile); + query = sqlite3_mprintf ("REPLACE INTO tiles (filename, etag, size) VALUES (%Q, %Q, %d)", champlain_tile_get_filename (tile), champlain_tile_get_etag (tile),