diff mbox series

[bug#39258,v6,2/2] DRAFT scripts: package: Use cache in 'find-packages-by-description'.

Message ID 20210715073328.212123-3-zimon.toutoune@gmail.com
State New
Headers show
Series DRAFT "guix search" performances | expand

Checks

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

Commit Message

zimoun July 15, 2021, 7:33 a.m. UTC
* guix/scripts/package.scm (find-packages-by-description): Replace
'fold-packages' by 'fold-available-packages'.
---
 guix/scripts/package.scm | 46 +++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 694959d326..ff2aed6905 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -8,7 +8,7 @@ 
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
-;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
+;;; Copyright © 2020, 2021 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -181,17 +181,39 @@  hooks\" run when building the profile."
   "Return a list of pairs: packages whose name, synopsis, description,
 or output matches at least one of REGEXPS sorted by relevance, and its
 non-zero relevance score."
-  (let ((matches (fold-packages (lambda (package result)
-                                  (if (package-superseded package)
-                                      result
-                                      (match (package-relevance package
-                                                                regexps)
-                                        ((? zero?)
-                                         result)
-                                        (score
-                                         (cons (cons package score)
-                                               result)))))
-                                '())))
+  (define (read-package-from module symbol)
+    (module-ref (resolve-interface module) symbol))
+
+  (let ((matches (fold-available-packages
+                  (lambda* (name version result
+                                 #:key outputs description synopsis location
+                                 module symbol
+                                 deprecated?
+                                 #:allow-other-keys)
+                    (if deprecated?
+                        result
+                        (let* ((package
+                                 (package
+                                   (name name)
+                                   (version version)
+                                   (source #f)
+                                   (build-system #f)
+                                   (outputs outputs)
+                                   (synopsis synopsis)
+                                   (description description)
+                                   (home-page #f)
+                                   (license #f)
+                                   (location location))))
+                          (match (package-relevance package
+                                                    regexps)
+                            ((? zero?)
+                             result)
+                            (score
+                             (cons (cons (read-package-from module symbol)
+                                         score)
+                                   result))))))
+                  '())))
+
     (sort matches
           (lambda (m1 m2)
             (match m1