Subject: [bug#42338] [PATCH v3 4/7] guix: import: composer: Use memoization.

From: Nicolas Graves <[email-masked]>
Date: Tue, 26 Sep 2023 12:31:41 +0200

---
 guix/import/composer.scm | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/guix/import/composer.scm b/guix/import/composer.scm
index c152f402bb..177dc63092 100644
--- a/guix/import/composer.scm
+++ b/guix/import/composer.scm
@@ -27,6 +27,7 @@ (define-module (guix import composer)
   #:use-module (guix import json)
   #:use-module (guix import utils)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix memoization)
   #:use-module (guix packages)
   #:use-module (guix serialization)
   #:use-module (guix upstream)
@@ -197,16 +198,18 @@ (define (make-php-sexp composer-package)
                            ((license) license)
                            (_ license)))))))))
 
-(define* (composer->guix-package package-name #:optional version)
-  "Fetch the metadata for PACKAGE-NAME from packagist.org, and return the
+(define composer->guix-package
+  (memoize
+   (lambda* (package-name #:key version #:allow-other-keys)
+     "Fetch the metadata for PACKAGE-NAME from packagist.org, and return the
 `package' s-expression corresponding to that package, or #f on failure."
-  (let ((package (composer-fetch package-name version)))
-    (and package
-         (let* ((package (json->composer-package package))
-                (dependencies-names (composer-package-require package))
-                (dev-dependencies-names (composer-package-dev-require package)))
-           (values (make-php-sexp package)
-                   (append dependencies-names dev-dependencies-names))))))
+     (let ((package (composer-fetch package-name version)))
+       (and package
+            (let* ((package (json->composer-package package))
+                   (dependencies-names (composer-package-require package))
+                   (dev-dependencies-names (composer-package-dev-require package)))
+              (values (make-php-sexp package)
+                      (append dependencies-names dev-dependencies-names))))))))
 
 (define (guix-name->composer-name name)
   "Given a guix package name, return the name of the package in Packagist."
@@ -265,6 +268,7 @@ (define %composer-updater
    (import latest-release)))
 
 (define* (composer-recursive-import package-name #:optional version)
-  (recursive-import package-name '()
+  (recursive-import package-name
+                    #:version version
                     #:repo->guix-package composer->guix-package
                     #:guix-name php-package-name))
-- 
2.41.0