From a1c1a84cdd63839f62c592412000ec613fb15894 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 14 Mar 2024 12:47:28 +0000 Subject: Initialise the recent changes count --- nar-herder/database.scm | 18 ++++++++++++++++++ nar-herder/recent-changes.scm | 5 +++++ 2 files changed, 23 insertions(+) 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))) -- cgit v1.2.3