aboutsummaryrefslogtreecommitdiff
path: root/nar-herder/database.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-02-06 16:06:20 +0100
committerChristopher Baines <mail@cbaines.net>2023-02-06 16:06:20 +0100
commit24ece550f538fa71927eddc6595bc81acfa60225 (patch)
tree3a18ffdeaa873fee47a0e41fc6ee619dd8a25e25 /nar-herder/database.scm
parentd3d9a365fc9aa09c3d6e4d5b80126976d4b39961 (diff)
downloadnar-herder-24ece550f538fa71927eddc6595bc81acfa60225.tar
nar-herder-24ece550f538fa71927eddc6595bc81acfa60225.tar.gz
Speed up removing narinfos
Using database-select-narinfo-by-hash will use an index.
Diffstat (limited to 'nar-herder/database.scm')
-rw-r--r--nar-herder/database.scm31
1 files changed, 8 insertions, 23 deletions
diff --git a/nar-herder/database.scm b/nar-herder/database.scm
index 8ddfe6f..e5e4905 100644
--- a/nar-herder/database.scm
+++ b/nar-herder/database.scm
@@ -28,6 +28,7 @@
#:use-module (sqlite3)
#:use-module (fibers)
#:use-module (prometheus)
+ #:use-module (guix store)
#:use-module (guix narinfo)
#:use-module (guix derivations)
#:use-module (nar-herder utils)
@@ -638,26 +639,6 @@ INSERT INTO narinfo_tags (narinfo_id, tag_id) VALUES (:narinfo_id, :tag_id)"
(define* (database-remove-narinfo database store-path
#:key change-datetime)
- (define (store-path->narinfo-id db)
- (let ((statement
- (sqlite-prepare
- db
- "
-SELECT id FROM narinfos WHERE store_path = :store_path"
- #:cache? #t)))
-
- (sqlite-bind-arguments
- statement
- #:store_path store-path)
-
- (let ((result
- (and=> (sqlite-step statement)
- (lambda (row)
- (vector-ref row 0)))))
- (sqlite-reset statement)
-
- result)))
-
(define (remove-narinfo-record db id)
(let ((statement
(sqlite-prepare
@@ -755,9 +736,13 @@ DELETE FROM narinfo_tags WHERE narinfo_id = :narinfo_id"
(database-call-with-transaction
database
(lambda (db)
- (let ((narinfo-id (store-path->narinfo-id db)))
- (if narinfo-id
- (begin
+ (let ((narinfo-details
+ (database-select-narinfo-by-hash
+ database
+ (store-path-hash-part store-path))))
+ (if narinfo-details
+ (let ((narinfo-id (assq-ref narinfo-details
+ 'id)))
(if change-datetime
(insert-change-with-datetime db store-path
change-datetime)