[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
18/20: squash! Optimize 'insert-package'.
From: |
guix-commits |
Subject: |
18/20: squash! Optimize 'insert-package'. |
Date: |
Sun, 4 Jun 2023 17:34:42 -0400 (EDT) |
civodul pushed a commit to branch wip-guix-index
in repository guix.
commit df59924abb90d565aff818fc7ee5d697bd87aa37
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Jun 4 22:26:20 2023 +0200
squash! Optimize 'insert-package'.
That makes 'guix locate -m store -u' slightly faster by not computing
the derivation of an already-indexed package.
---
guix/scripts/locate.scm | 49 ++++++++++++++++++++++++++++++++++---------------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/guix/scripts/locate.scm b/guix/scripts/locate.scm
index a8a8f96be5..bc30b5269f 100644
--- a/guix/scripts/locate.scm
+++ b/guix/scripts/locate.scm
@@ -217,13 +217,12 @@ VALUES (:name, :basename, :directory);"
(sqlite-exec db "begin immediate;")
;; 1 record per output
(for-each (lambda (output)
- (let ((out (if (string=? "out" output) "" output)))
- (sqlite-reset stmt-insert-package)
- (sqlite-bind-arguments stmt-insert-package
- #:name package
- #:version version
- #:output out)
- (sqlite-fold (const #t) #t stmt-insert-package)))
+ (sqlite-reset stmt-insert-package)
+ (sqlite-bind-arguments stmt-insert-package
+ #:name package
+ #:version version
+ #:output output)
+ (sqlite-fold (const #t) #t stmt-insert-package))
outputs)
(sqlite-bind-arguments stmt-select-package
#:name package
@@ -274,14 +273,34 @@ VALUES (:name, :basename, :directory);"
(define (insert-package db package)
"Insert all the files of PACKAGE into DB."
- (mlet %store-monad ((drv (package->derivation package #:graft? #f)))
- (match (derivation->output-paths drv)
- (((labels . directories) ...)
- (when (every file-exists? directories)
- (insert-files
- db (package-name package) (package-version package) (package-outputs
package)
- directories))
- (return #t)))))
+ (define stmt-select-package-output
+ (sqlite-prepare db "\
+SELECT output FROM Packages WHERE name = :name AND version = :version"
+ #:cache? #t))
+
+ (define (known-outputs package)
+ ;; Return the list of outputs of PACKAGE already in DB.
+ (sqlite-bind-arguments stmt-select-package-output
+ #:name (package-name package)
+ #:version (package-version package))
+ (match (sqlite-fold cons '() stmt-select-package-output)
+ ((#(outputs ...)) outputs)
+ (() '())))
+
+ (with-monad %store-monad
+ ;; Since calling 'package->derivation' is expensive, do not call it if the
+ ;; outputs of PACKAGE at VERSION are already in DB.
+ (munless (lset= string=?
+ (known-outputs package)
+ (package-outputs package))
+ (mlet %store-monad ((drv (package->derivation package #:graft? #f)))
+ (match (derivation->output-paths drv)
+ (((labels . directories) ...)
+ (when (every file-exists? directories)
+ (insert-files
+ db (package-name package) (package-version package)
(package-outputs package)
+ directories))
+ (return #t)))))))
(define (insert-packages-with-progress db packages insert-package)
"Insert PACKAGES into DB with progress bar reporting, calling INSERT-PACKAGE
- branch wip-guix-index created (now 861a4e42e7), guix-commits, 2023/06/04
- 04/20: squash! "--db-path" -> "--database"., guix-commits, 2023/06/04
- 07/20: squash! Don't insert directory if it's already present., guix-commits, 2023/06/04
- 08/20: squash! Remove debugging statements., guix-commits, 2023/06/04
- 12/20: squash! Add one variant of each package (name/version pair)., guix-commits, 2023/06/04
- 13/20: squash! Create database when it doesn't already exist., guix-commits, 2023/06/04
- 16/20: squash! Simplify '--help'., guix-commits, 2023/06/04
- 18/20: squash! Optimize 'insert-package'.,
guix-commits <=
- 19/20: squash! Show output name except for "out"; remove '-d'., guix-commits, 2023/06/04
- 02/20: DRAFT Add 'guix index'., guix-commits, 2023/06/04
- 03/20: squash! Update test., guix-commits, 2023/06/04
- 05/20: squash! Improve error reporting and i18n., guix-commits, 2023/06/04
- 01/20: store: Tolerate non-existent GC root directories., guix-commits, 2023/06/04
- 06/20: squash! "with-method" -> "method", guix-commits, 2023/06/04
- 09/20: squash! Choose system-wide database if it's more recent., guix-commits, 2023/06/04
- 11/20: squash! Keep store prefix in database., guix-commits, 2023/06/04
- 15/20: squash! Rename to 'guix locate'., guix-commits, 2023/06/04
- 17/20: squash! Migrate schema when opening., guix-commits, 2023/06/04