guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/02: hydra: build-package-metadata: Compress JSON files.


From: Ludovic Courtès
Subject: 01/02: hydra: build-package-metadata: Compress JSON files.
Date: Mon, 9 Oct 2023 08:28:18 -0400 (EDT)

civodul pushed a commit to branch master
in repository maintenance.

commit 1123fd81ce2082d25d5262311ad4eae50c197ad2
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Oct 9 10:57:31 2023 +0200

    hydra: build-package-metadata: Compress JSON files.
    
    * hydra/build-package-metadata.scm (write-json): Use
    ‘call-with-gzip-output-port’.
    (main): Append “.gz” to JSON file names.
    * hydra/modules/sysadmin/nginx.scm (guix.gnu.org-other-locations): Add
    “gzip_static” and “gunzip” directives on /packages.json and
    /sources.json.
---
 hydra/build-package-metadata.scm | 23 +++++++++++++++++------
 hydra/modules/sysadmin/nginx.scm |  2 ++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/hydra/build-package-metadata.scm b/hydra/build-package-metadata.scm
index d110d4d..44a3c84 100755
--- a/hydra/build-package-metadata.scm
+++ b/hydra/build-package-metadata.scm
@@ -39,6 +39,7 @@
              (guix svn-download)
              (guix hg-download)
              (json)
+             (zlib)
              (web uri)
              (ice-9 match)
              (ice-9 vlist)
@@ -239,11 +240,21 @@ superseded packages."
   (list->vector (map package->json (all-packages))))
 
 (define (write-json json file)
-  "Serialize JSON to FILE."
-  (with-atomic-file-output file
-    (lambda (port)
-      (scm->json json port)
-      (chmod port #o644))))
+  "Serialize and compress JSON to FILE."
+  (let ((pivot (string-append file ".tmp")))
+    ;; Note: 'with-atomic-file-output' doesn't work well with
+    ;; 'call-with-gzip-output-port' since the latter closes its underlying
+    ;; port.
+    (call-with-output-file pivot
+      (lambda (port)
+        (chmod port #o644)
+        (call-with-gzip-output-port port
+          (lambda (port)
+            (set-port-encoding! port "UTF-8")
+            (scm->json json port))
+          #:buffer-size (expt 2 16)
+          #:level 9)))
+    (rename-file pivot file)))
 
 
 ;;;
@@ -258,7 +269,7 @@ superseded packages."
                  (write-json (thunk)
                              (string-append directory "/" file)))
                (list packages-json sources-json)
-               '("packages.json" "sources.json")))
+               '("packages.json.gz" "sources.json.gz")))
     ((command . _)
      (leave (G_ "Usage: ~a DIRECTORY
 
diff --git a/hydra/modules/sysadmin/nginx.scm b/hydra/modules/sysadmin/nginx.scm
index e6eaf06..f314075 100644
--- a/hydra/modules/sysadmin/nginx.scm
+++ b/hydra/modules/sysadmin/nginx.scm
@@ -704,11 +704,13 @@ synonymous IETF language tags that should be mapped to 
the same $lang."
    (nginx-location-configuration
     (uri "= /packages.json")
     (body (list "if_modified_since exact;"
+                "gzip_static always; gunzip on;\n"
                 "root /srv/package-metadata;")))
 
    (nginx-location-configuration
     (uri "= /sources.json")
     (body (list "if_modified_since exact;"
+                "gzip_static always; gunzip on;\n"
                 "root /srv/package-metadata;")))
 
    (nginx-location-configuration                  ;certbot



reply via email to

[Prev in Thread] Current Thread [Next in Thread]