diff mbox series

[bug#38408,v17,4/8] import: crate: Memorize crate->guix-package.

Message ID 31b17421ebdbd8b2e8037b1163a7c90835dea7e6.1605552418.git.h.goebel@crazy-compilers.com
State Accepted
Headers show
Series New take continued: Semantic version aware recursive | expand

Checks

Context Check Description
cbaines/submitting builds success
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Hartmut Goebel Nov. 16, 2020, 7:07 p.m. UTC
From: Martin Becze <mjbecze@riseup.net>

This adds memorization to procedures that involve network lookups.
'lookup-crate*' is used on every dependency of a package to get its version
list. It is also used to lookup a package's metadata. 'crate-recursive-import'
is also memorized since creating the same package twice will trigger a lookup
on its dependencies.

* guix/import/crate.scm (lookup-crate*): New procedure.
  (crate->guix-package): Memorize package metadata lookups.
  (crate-recursive-import): Memorize package creation.
---
 guix/import/crate.scm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 5498d1f0ff..c830449555 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -27,6 +27,7 @@ 
   #:use-module (guix import json)
   #:use-module (guix import utils)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix memoization)
   #:use-module (guix monads)
   #:use-module (guix packages)
   #:use-module (guix upstream)
@@ -110,6 +111,8 @@  record or #f if it was not found."
                (json->crate `(,@alist
                               ("actual_versions" . ,versions))))))))
 
+(define lookup-crate* (memoize lookup-crate))
+
 (define (crate-version-dependencies version)
   "Return the list of <crate-dependency> records of VERSION, a
 <crate-version>."
@@ -215,7 +218,7 @@  version of CRATE-NAME."
         (eq? (crate-dependency-kind dependency) 'normal)))
 
   (define crate
-    (lookup-crate crate-name))
+    (lookup-crate* crate-name))
 
   (define version-number
     (and crate
@@ -247,7 +250,7 @@  version of CRATE-NAME."
   (define (sort-map-dependencies deps)
     (sort (map (lambda (dep)
                  (let* ((name (crate-dependency-id dep))
-                        (crate (lookup-crate name))
+                        (crate (lookup-crate* name))
                         (req (crate-dependency-requirement dep))
                         (ver (find-crate-version crate req)))
                    (list name
@@ -276,7 +279,7 @@  version of CRATE-NAME."
 
 (define* (crate-recursive-import crate-name #:key version)
   (recursive-import crate-name
-                    #:repo->guix-package crate->guix-package
+                    #:repo->guix-package (memoize crate->guix-package)
                     #:version version
                     #:guix-name crate-name->package-name))