setup/xref: fix load-collections-xref
for multple uses
When the result of `load-collections-xref` is used in multiple document renderings (e.g., multiple calls to `render`), then an intenal cache behaved the wrong way. Fixing the problem required an extension to `scribble/xref`.
This commit is contained in:
parent
462a4f5c37
commit
f66fff1ca9
|
@ -6,7 +6,7 @@
|
||||||
["base" #:version "6.5.0.2"]
|
["base" #:version "6.5.0.2"]
|
||||||
"net-lib"
|
"net-lib"
|
||||||
"sandbox-lib"
|
"sandbox-lib"
|
||||||
["scribble-lib" #:version "1.14"]
|
["scribble-lib" #:version "1.34"]
|
||||||
"racket-index"))
|
"racket-index"))
|
||||||
(define build-deps '("rackunit-doc"
|
(define build-deps '("rackunit-doc"
|
||||||
"compatibility"
|
"compatibility"
|
||||||
|
|
|
@ -2157,11 +2157,10 @@ Returns @racket[#t] if cross-installation mode has been detected,
|
||||||
@defproc[(load-collections-xref [on-load (-> any/c) (lambda () (void))])
|
@defproc[(load-collections-xref [on-load (-> any/c) (lambda () (void))])
|
||||||
xref?]{
|
xref?]{
|
||||||
|
|
||||||
Like @racket[load-xref], but automatically find all cross-reference files for
|
Either creates and caches or returns a cached cross-reference record
|
||||||
manuals that have been installed with @exec{raco setup}.
|
created with @racket[make-collections-xref]. The @racket[on-load]
|
||||||
|
function is called only when a previously cached record is not
|
||||||
A cached copy of cross-reference information can be used, in which
|
returned.}
|
||||||
case @racket[on-load] is @emph{not} called.}
|
|
||||||
|
|
||||||
|
|
||||||
@defproc[(make-collections-xref [#:no-user? no-user? any/c #f]
|
@defproc[(make-collections-xref [#:no-user? no-user? any/c #f]
|
||||||
|
@ -2171,7 +2170,9 @@ case @racket[on-load] is @emph{not} called.}
|
||||||
[#:register-shutdown! register-shutdown! ((-> any) . -> . any) void])
|
[#:register-shutdown! register-shutdown! ((-> any) . -> . any) void])
|
||||||
xref?]{
|
xref?]{
|
||||||
|
|
||||||
Like @racket[load-collections-xref], but takes advantage of a
|
Like @racket[load-xref], but automatically finds all cross-reference
|
||||||
|
files for manuals that have been installed with @exec{raco setup}.
|
||||||
|
The resulting cross-reference record takes advantage of a
|
||||||
cross-reference database @racket[db-path], when support is available,
|
cross-reference database @racket[db-path], when support is available,
|
||||||
to delay the loading of cross-reference details until needed.
|
to delay the loading of cross-reference details until needed.
|
||||||
|
|
||||||
|
|
|
@ -103,20 +103,25 @@
|
||||||
(close p))))
|
(close p))))
|
||||||
(when main-db (close main-db))
|
(when main-db (close main-db))
|
||||||
(when user-db (close user-db))))
|
(when user-db (close user-db))))
|
||||||
(define done-ht (make-hash)) ; tracks already-loaded documents
|
(define done-hts (make-hasheq)) ; tracks already-loaded documents per ci
|
||||||
(define forced-all? #f)
|
(define (get-done-ht use-id)
|
||||||
(define (force-all)
|
(or (hash-ref done-hts use-id #f)
|
||||||
|
(let ([ht (make-hash)])
|
||||||
|
(hash-set! done-hts use-id ht)
|
||||||
|
ht)))
|
||||||
|
(define forced-all?s (make-hasheq)) ; per ci: whether forced all
|
||||||
|
(define (force-all use-id)
|
||||||
;; force all documents
|
;; force all documents
|
||||||
(define thunks (get-reader-thunks no-user? no-main? quiet-fail? done-ht))
|
(define thunks (get-reader-thunks no-user? no-main? quiet-fail? (get-done-ht use-id)))
|
||||||
(set! forced-all? #t)
|
(hash-set! forced-all?s use-id #t)
|
||||||
(lambda ()
|
(lambda ()
|
||||||
;; return a procedure so we can produce a list of results:
|
;; return a procedure so we can produce a list of results:
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(for/list ([thunk (in-list thunks)])
|
(for/list ([thunk (in-list thunks)])
|
||||||
(thunk)))))
|
(thunk)))))
|
||||||
(lambda (key)
|
(lambda (key use-id)
|
||||||
(cond
|
(cond
|
||||||
[forced-all? #f]
|
[(hash-ref forced-all?s use-id #f) #f]
|
||||||
[key
|
[key
|
||||||
(define (try p)
|
(define (try p)
|
||||||
(and p
|
(and p
|
||||||
|
@ -140,11 +145,11 @@
|
||||||
(define dest (or (try main-db) (try user-db)))
|
(define dest (or (try main-db) (try user-db)))
|
||||||
(and dest
|
(and dest
|
||||||
(if (eq? dest #t)
|
(if (eq? dest #t)
|
||||||
(force-all)
|
(force-all use-id)
|
||||||
((dest->source done-ht quiet-fail?) dest)))]
|
((dest->source (get-done-ht use-id) quiet-fail?) dest)))]
|
||||||
[else
|
[else
|
||||||
(unless forced-all?
|
(unless (hash-ref forced-all?s use-id #f)
|
||||||
(force-all))])))
|
(force-all use-id))])))
|
||||||
|
|
||||||
(define (get-reader-thunks no-user? no-main? quiet-fail? done-ht)
|
(define (get-reader-thunks no-user? no-main? quiet-fail? done-ht)
|
||||||
(map (dest->source done-ht quiet-fail?)
|
(map (dest->source done-ht quiet-fail?)
|
||||||
|
@ -165,8 +170,9 @@
|
||||||
#:register-shutdown! [register-shutdown! void])
|
#:register-shutdown! [register-shutdown! void])
|
||||||
(if (doc-db-available?)
|
(if (doc-db-available?)
|
||||||
(load-xref null
|
(load-xref null
|
||||||
#:demand-source (make-key->source db-path no-user? no-main? quiet-fail?
|
#:demand-source-for-use
|
||||||
register-shutdown!))
|
(make-key->source db-path no-user? no-main? quiet-fail?
|
||||||
|
register-shutdown!))
|
||||||
(load-xref (get-reader-thunks no-user? no-main? quiet-fail? (make-hash)))))
|
(load-xref (get-reader-thunks no-user? no-main? quiet-fail? (make-hash)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user