cbaines pushed a commit to branch trunk
in repository data-service.

commit 167b7d029e249c46bfc2aba5ebf11f7968b15db0
Author: Christopher Baines <[email protected]>
AuthorDate: Tue Mar 11 19:38:56 2025 +0000

    Extract out code for updating derivation source file nars
    
    So that this can be used to fix some which have crept in to the database as
    placeholders.
---
 guix-data-service/jobs/load-new-guix-revision.scm | 83 +++++++++++++----------
 1 file changed, 46 insertions(+), 37 deletions(-)

diff --git a/guix-data-service/jobs/load-new-guix-revision.scm 
b/guix-data-service/jobs/load-new-guix-revision.scm
index 1534e05..9638db0 100644
--- a/guix-data-service/jobs/load-new-guix-revision.scm
+++ b/guix-data-service/jobs/load-new-guix-revision.scm
@@ -1006,6 +1006,48 @@
        1000
        missing-file-names))))
 
+(define (compute-and-update-derivation-source-file-nar
+         postgresql-connection-pool
+         id
+         source-file)
+  (let ((nar-bytevector
+         (call-with-values
+             (lambda ()
+               (open-bytevector-output-port))
+           (lambda (port get-bytevector)
+             (unless (file-exists? source-file)
+               (raise-exception
+                (make-missing-store-item-error
+                 source-file)))
+             (write-file source-file port)
+             (let ((res (get-bytevector)))
+               (close-port port) ; maybe reduces memory?
+               res)))))
+    (let ((compressed-nar-bytevector
+           (call-with-values
+               (lambda ()
+                 (open-bytevector-output-port))
+             (lambda (port get-bytevector)
+               (call-with-lzip-output-port port
+                 (lambda (port)
+                   (put-bytevector port nar-bytevector))
+                 #:level 9)
+               (let ((res (get-bytevector)))
+                 (close-port port) ; maybe reduces memory?
+                 res))))
+          (hash
+           (bytevector->nix-base32-string
+            (sha256 nar-bytevector)))
+          (uncompressed-size
+           (bytevector-length nar-bytevector)))
+      (with-resource-from-pool postgresql-connection-pool conn
+        (update-derivation-source-file-nar
+         conn
+         id
+         hash
+         compressed-nar-bytevector
+         uncompressed-size)))))
+
 (define* (derivations-insert-sources postgresql-connection-pool
                                      call-with-utility-thread
                                      derivations
@@ -1044,43 +1086,10 @@ SELECT 1 FROM derivation_source_file_nars WHERE 
derivation_source_file_id = $1"
                   ;; avoid using too much memory
                   (call-with-utility-thread
                    (lambda ()
-                     (let ((nar-bytevector
-                            (call-with-values
-                                (lambda ()
-                                  (open-bytevector-output-port))
-                              (lambda (port get-bytevector)
-                                (unless (file-exists? source-file)
-                                  (raise-exception
-                                   (make-missing-store-item-error
-                                    source-file)))
-                                (write-file source-file port)
-                                (let ((res (get-bytevector)))
-                                  (close-port port) ; maybe reduces memory?
-                                  res)))))
-                       (let ((compressed-nar-bytevector
-                              (call-with-values
-                                  (lambda ()
-                                    (open-bytevector-output-port))
-                                (lambda (port get-bytevector)
-                                  (call-with-lzip-output-port port
-                                    (lambda (port)
-                                      (put-bytevector port nar-bytevector))
-                                    #:level 9)
-                                  (let ((res (get-bytevector)))
-                                    (close-port port) ; maybe reduces memory?
-                                    res))))
-                             (hash
-                              (bytevector->nix-base32-string
-                               (sha256 nar-bytevector)))
-                             (uncompressed-size
-                              (bytevector-length nar-bytevector)))
-                         (with-resource-from-pool postgresql-connection-pool 
conn
-                           (update-derivation-source-file-nar
-                            conn
-                            id
-                            hash
-                            compressed-nar-bytevector
-                            uncompressed-size))))))))
+                     (compute-and-update-derivation-source-file-nar
+                      postgresql-connection-pool
+                      id
+                      source-file)))))
               sources-ids
               sources)))))
      derivation-ids

Reply via email to