From 24ece550f538fa71927eddc6595bc81acfa60225 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 6 Feb 2023 16:06:20 +0100 Subject: Speed up removing narinfos Using database-select-narinfo-by-hash will use an index. --- nar-herder/database.scm | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'nar-herder') 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) -- cgit v1.2.3