substitute: Optimize hash-part-to-path conversion on non-200 responses.
Previously this operation was linear in the number of requests and involved costly calls to 'string-contains'. * guix/scripts/substitute.scm (fetch-narinfos)[hash-part->path]: New procedure. [handle-narinfo-response]: Use it for caching when CODE is not 200.
This commit is contained in:
		
							parent
							
								
									0cf9f9b1e3
								
							
						
					
					
						commit
						3d3e93b3f9
					
				
					 1 changed files with 13 additions and 3 deletions
				
			
		| 
						 | 
					@ -47,6 +47,7 @@
 | 
				
			||||||
  #:use-module (ice-9 format)
 | 
					  #:use-module (ice-9 format)
 | 
				
			||||||
  #:use-module (ice-9 ftw)
 | 
					  #:use-module (ice-9 ftw)
 | 
				
			||||||
  #:use-module (ice-9 binary-ports)
 | 
					  #:use-module (ice-9 binary-ports)
 | 
				
			||||||
 | 
					  #:use-module (ice-9 vlist)
 | 
				
			||||||
  #:use-module (rnrs bytevectors)
 | 
					  #:use-module (rnrs bytevectors)
 | 
				
			||||||
  #:use-module (srfi srfi-1)
 | 
					  #:use-module (srfi srfi-1)
 | 
				
			||||||
  #:use-module (srfi srfi-9)
 | 
					  #:use-module (srfi srfi-9)
 | 
				
			||||||
| 
						 | 
					@ -609,6 +610,17 @@ if file doesn't exist, and the narinfo otherwise."
 | 
				
			||||||
                url (* 100. (/ done (length paths))))
 | 
					                url (* 100. (/ done (length paths))))
 | 
				
			||||||
        (set! done (+ 1 done)))))
 | 
					        (set! done (+ 1 done)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  (define hash-part->path
 | 
				
			||||||
 | 
					    (let ((mapping (fold (lambda (path result)
 | 
				
			||||||
 | 
					                           (vhash-cons (store-path-hash-part path) path
 | 
				
			||||||
 | 
					                                       result))
 | 
				
			||||||
 | 
					                         vlist-null
 | 
				
			||||||
 | 
					                         paths)))
 | 
				
			||||||
 | 
					      (lambda (hash)
 | 
				
			||||||
 | 
					        (match (vhash-assoc hash mapping)
 | 
				
			||||||
 | 
					          (#f #f)
 | 
				
			||||||
 | 
					          ((_ . path) path)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  (define (handle-narinfo-response request response port result)
 | 
					  (define (handle-narinfo-response request response port result)
 | 
				
			||||||
    (let* ((code   (response-code response))
 | 
					    (let* ((code   (response-code response))
 | 
				
			||||||
           (len    (response-content-length response))
 | 
					           (len    (response-content-length response))
 | 
				
			||||||
| 
						 | 
					@ -627,9 +639,7 @@ if file doesn't exist, and the narinfo otherwise."
 | 
				
			||||||
            (if len
 | 
					            (if len
 | 
				
			||||||
                (get-bytevector-n port len)
 | 
					                (get-bytevector-n port len)
 | 
				
			||||||
                (read-to-eof port))
 | 
					                (read-to-eof port))
 | 
				
			||||||
            (cache-narinfo! url
 | 
					            (cache-narinfo! url (hash-part->path hash-part) #f
 | 
				
			||||||
                            (find (cut string-contains <> hash-part) paths)
 | 
					 | 
				
			||||||
                            #f
 | 
					 | 
				
			||||||
                            (if (= 404 code)
 | 
					                            (if (= 404 code)
 | 
				
			||||||
                                ttl
 | 
					                                ttl
 | 
				
			||||||
                                %narinfo-transient-error-ttl))
 | 
					                                %narinfo-transient-error-ttl))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue