From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:59226) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyxAZ-000457-JE for guix-patches@gnu.org; Tue, 04 Feb 2020 07:19:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyxAX-0003YH-D9 for guix-patches@gnu.org; Tue, 04 Feb 2020 07:19:07 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36757) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyxAX-0003XL-8S for guix-patches@gnu.org; Tue, 04 Feb 2020 07:19:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iyxAX-0003md-5V for guix-patches@gnu.org; Tue, 04 Feb 2020 07:19:05 -0500 Subject: [bug#38408] [PATCH v9 6/8] guix: import: crate: memorize crate->guix-package Resent-Message-ID: From: Martin Becze Date: Tue, 4 Feb 2020 07:18:23 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 38408@debbugs.gnu.org Cc: ludo@gnu.org, efraim@flashner.co.il, jsoo1@asu.edu, Martin Becze This adds memorization to procedures that involve network lookups. (mem-lookup-crate) is used on every dependency of a package to find it's versions. (mem-crate->guix-package) is needed becuase (topological-sort) depduplicates after dependencies have been turned into dependencies. * guix/import/crate.scm (mem-crate->guix-package, mem-lookup-crate) --- guix/import/crate.scm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/guix/import/crate.scm b/guix/import/crate.scm index a82e5e877a..630f4d3749 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -28,6 +28,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) @@ -108,6 +109,8 @@ record or #f if it was not found." (json->crate `(,@alist ("actual_versions" . ,versions)))))))) +(define mem-lookup-crate (memoize lookup-crate)) + (define (crate-version-dependencies version) "Return the list of records of VERSION, a ." @@ -213,7 +216,7 @@ latest version of CRATE-NAME." (eq? (crate-dependency-kind dependency) 'normal))) (define crate - (lookup-crate crate-name)) + (mem-lookup-crate crate-name)) (define version-number (or version @@ -235,7 +238,7 @@ latest version of CRATE-NAME." containing pairs of (name version)" (sort (map (lambda (dep) (let* ((name (crate-dependency-id dep)) - (crate (lookup-crate name)) + (crate (mem-lookup-crate name)) (req (crate-dependency-requirement dep)) (ver (find-version crate req))) (list name @@ -262,9 +265,11 @@ latest version of CRATE-NAME." string->license)) cargo-inputs)))) +(define mem-crate->guix-package (memoize crate->guix-package)) + (define* (crate-recursive-import crate-name #:key version) (recursive-import crate-name - #:repo->guix-package crate->guix-package + #:repo->guix-package mem-crate->guix-package #:version version #:guix-name crate-name->package-name)) -- 2.25.0