aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-05-25 11:08:20 +0100
committerChristopher Baines <mail@cbaines.net>2020-05-25 11:08:20 +0100
commit9265949cf669b9e861bc85a1f1c3954cf4e216cc (patch)
tree89579191bda64514cbd4d5023bf33081a8b7c089 /src
parent68a6912ce2e5d281bc7b45bf447b7695f5425388 (diff)
downloadcuirass-9265949cf669b9e861bc85a1f1c3954cf4e216cc.tar
cuirass-9265949cf669b9e861bc85a1f1c3954cf4e216cc.tar.gz
cuirass: Perform some database "optimization" at startup.
Add a "optimize" step that occurs when starting up the main Curiass process. Currently this does two things, but could be extended to do more. The "PRAGMA optimize;" command prompts SQLite to ANALYZE tables where that might help. The "PRAGMA wal_checkpoint(TRUNCATE);" command has SQLite process any unprocessed changes from the WAL file, then truncate it to 0 bytes. I've got no data to suggest this helps with performance, but I'm hoping that going from a large WAL file to a small one occasionally might be useful. * src/cuirass/database.scm (db-optimize): New procedure. * bin/cuirass.in (main): Run it.
Diffstat (limited to 'src')
-rw-r--r--src/cuirass/database.scm8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index f80585e..e81ead0 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -38,6 +38,7 @@
db-init
db-open
db-close
+ db-optimize
db-add-specification
db-remove-specification
db-get-specifications
@@ -277,6 +278,13 @@ database object."
"Close database object DB."
(sqlite-close db))
+(define* (db-optimize #:optional (db-file (%package-database)))
+ "Open the database and perform optimizations."
+ (let ((db (db-open db-file)))
+ (sqlite-exec db "PRAGMA optimize;")
+ (sqlite-exec db "PRAGMA wal_checkpoint(TRUNCATE);")
+ (db-close db)))
+
(define (last-insert-rowid db)
(vector-ref (car (sqlite-exec db "SELECT last_insert_rowid();"))
0))