aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-03-14 12:47:28 +0000
committerChristopher Baines <mail@cbaines.net>2024-03-14 13:01:17 +0000
commita1c1a84cdd63839f62c592412000ec613fb15894 (patch)
treee6945b86e6922d6a3571602222151e328f9c8949
parent6cd5917688580ddf31a30429bceccf1346fa204a (diff)
downloadnar-herder-a1c1a84cdd63839f62c592412000ec613fb15894.tar
nar-herder-a1c1a84cdd63839f62c592412000ec613fb15894.tar.gz
Initialise the recent changes count
-rw-r--r--nar-herder/database.scm18
-rw-r--r--nar-herder/recent-changes.scm5
2 files changed, 23 insertions, 0 deletions
diff --git a/nar-herder/database.scm b/nar-herder/database.scm
index 7a550ec..c8171a3 100644
--- a/nar-herder/database.scm
+++ b/nar-herder/database.scm
@@ -46,6 +46,7 @@
database-select-narinfo-by-hash
database-select-narinfo-contents-by-hash
+ database-count-recent-changes
database-select-recent-changes
database-select-latest-recent-change-datetime
database-get-recent-changes-id-for-deletion
@@ -893,6 +894,23 @@ SELECT id, contents FROM narinfos WHERE substr(store_path, 12, 32) = :hash"
(_
(values #f #f)))))))))
+(define (database-count-recent-changes database)
+ (call-with-worker-thread
+ (database-reader-thread-channel database)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT COUNT(*) FROM recent_changes"
+ #:cache? #t)))
+
+ (let ((result
+ (match (sqlite-step statement)
+ (#(count) count))))
+ (sqlite-reset statement)
+ result)))))
+
(define* (database-select-recent-changes database after-date #:key (limit 8192))
(call-with-worker-thread
(database-reader-thread-channel database)
diff --git a/nar-herder/recent-changes.scm b/nar-herder/recent-changes.scm
index d95410e..e4fe7d1 100644
--- a/nar-herder/recent-changes.scm
+++ b/nar-herder/recent-changes.scm
@@ -118,6 +118,11 @@
(spawn-fiber
(lambda ()
+ (let ((recent-changes-count
+ (database-count-recent-changes database)))
+ (metric-set recent-changes-count-metric recent-changes-count)
+ (log-msg 'DEBUG recent-changes-count " recent changes in the database"))
+
(log-msg 'DEBUG "starting to listen for recent changes")
(let ((after-initial
(database-select-latest-recent-change-datetime database)))