Index: cache.rkt ================================================================== --- cache.rkt +++ cache.rkt @@ -34,11 +34,11 @@ series-grouped-list) ;; Cache DB and Schemas (define DBFILE (build-path (current-project-root) "vitreous.sqlite")) -(define cache-conn (sqlite3-connect #:database DBFILE #:mode 'create)) +(define cache-conn (make-parameter (sqlite3-connect #:database DBFILE #:mode 'create))) (define current-plain-title (make-parameter "void")) (define-schema cache:article #:table "articles" ([id id/f #:primary-key #:auto-increment] @@ -97,23 +97,23 @@ ([html string/f] [published date/f] [series-page symbol/f])) (define (init-cache-db!) - (create-table! cache-conn 'cache:article) - (create-table! cache-conn 'cache:note) - (create-table! cache-conn 'cache:series) - (create-table! cache-conn 'cache:index-entry)) + (create-table! (cache-conn) 'cache:article) + (create-table! (cache-conn) 'cache:note) + (create-table! (cache-conn) 'cache:series) + (create-table! (cache-conn) 'cache:index-entry)) (define (delete-article! page) - (query-exec cache-conn + (query-exec (cache-conn) (~> (from cache:article #:as a) (where (= a.page ,(format "~a" page))) delete))) (define (delete-notes! page) - (query-exec cache-conn + (query-exec (cache-conn) (~> (from cache:note #:as n) (where (= n.page ,(format "~a" page))) delete))) ;; @@ -179,11 +179,11 @@ (order-by ([a.published ,ord])) (project-onto listing-schema))) ;; Get all the a list of the HTML all the results in a query (define (listing-htmls list-query) - (for/list ([l (in-entities cache-conn list-query)]) + (for/list ([l (in-entities (cache-conn) list-query)]) (listing-html l))) ;; Return cached HTML of articles and/or notes, fenced within a style txexpr to prevent it being ;; escaped by ->html. See also: definition of `unfence` @@ -207,17 +207,17 @@ ;; ;; ~~~ Fetching series ~~~ ;; (define (series-grouped-list) - (~> (for/list ([row (in-entities cache-conn (from cache:series #:as s))]) row) + (~> (for/list ([row (in-entities (cache-conn) (from cache:series #:as s))]) row) (group-list-by cache:series-noun-plural _ string-ci=?))) ;; Preloads the SQLite cache with info about each series. ;; I may not actually need this but I’m leaving it for now. (define (preheat-series!) - (query-exec cache-conn + (query-exec (cache-conn) (~> (from cache:series #:as s) (where 1) delete)) (define series-rows (for/list ([series-pagenode (in-list (cdr (series-pagetree)))]) @@ -226,6 +226,6 @@ #:page series-pagenode #:title (hash-ref series-metas 'title) #:published (hash-ref series-metas 'published "") #:noun-plural (hash-ref series-metas 'noun-plural "") #:noun-singular (hash-ref series-metas 'noun-singular "")))) - (void (apply insert! cache-conn series-rows))) + (void (apply insert! (cache-conn) series-rows))) Index: crystalize.rkt ================================================================== --- crystalize.rkt +++ crystalize.rkt @@ -10,11 +10,11 @@ racket/match racket/string txexpr pollen/template (except-in pollen/core select) ; avoid conflict with deta -) + ) (require "dust.rkt" "cache.rkt" "snippets-html.rkt") (provide parse-and-cache-article! cache-series!) @@ -47,11 +47,11 @@ [listing-short (html$-article-listing-short pagenode pubdate title-html)] [notes-section-html (cache-notes! pagenode title-plain note-txprs)]) (cache-index-entries! pagenode doc) ; note original doc is used here (current-plain-title title-plain) (delete-article! pagenode) - (insert-one! cache-conn + (insert-one! (cache-conn) (make-cache:article #:page pagenode #:title-plain title-plain #:title-html-flow title-html #:title-specified? title-specified? @@ -130,12 +130,12 @@ [else ""])) ;; ~~~ Notes ~~~ (define (cache-notes! pagenode parent-title note-txprs) - (query-exec cache-conn (delete (~> (from cache:note #:as n) - (where (= n.page ,(symbol->string pagenode)))))) + (query-exec (cache-conn) (delete (~> (from cache:note #:as n) + (where (= n.page ,(symbol->string pagenode)))))) (cond [(not (null? note-txprs)) (define note-htmls (for/list ([n (in-list note-txprs)]) (cache-note! n pagenode parent-title))) (html$-notes-section note-htmls)] @@ -162,11 +162,11 @@ [title-tx (make-note-title pagenode parent-title-plain)] [title-html (->html title-tx #:splice? #t)] [author (maybe-attr 'author attrs default-authorname)] [author-url (maybe-attr 'author-url attrs)] [content-html (html$-note-contents disp-mark disp-verb elems)]) - (insert-one! cache-conn + (insert-one! (cache-conn) (make-cache:note #:page pagenode #:html-anchor note-id #:title-html-flow title-html #:title-plain (tx-strs title-tx) @@ -222,29 +222,29 @@ ;; Save any index entries in doc to the SQLite cache. ;; Sub-entries are specified by "!" in the index key (define (cache-index-entries! pagenode doc) (define-values (_ entry-txs) (splitf-txexpr doc index-entry-txpr?)) ; Naive idempotence: delete and re-insert all index entries every time doc is rendered. - (query-exec cache-conn (delete (~> (from cache:index-entry #:as entry) - (where (= entry.page ,(symbol->string pagenode)))))) + (query-exec (cache-conn) (delete (~> (from cache:index-entry #:as entry) + (where (= entry.page ,(symbol->string pagenode)))))) (unless (null? entry-txs) (void - (apply insert! cache-conn + (apply insert! (cache-conn) (for/list ([etx (in-list entry-txs)]) (txexpr->index-entry etx pagenode)))))) ;; Save the current article to the `series` table of the SQLite cache ;; Should be called from a template for series pages (define (cache-series!) (define here-page (path->string (here-output-path))) - (query-exec cache-conn + (query-exec (cache-conn) (delete (~> (from cache:series #:as s) (where (= s.page ,here-page))))) (void - (insert-one! cache-conn + (insert-one! (cache-conn) (make-cache:series #:page (string->symbol here-page) #:title (hash-ref (current-metas) 'title) #:published (hash-ref (current-metas) 'published "") #:noun-plural (hash-ref (current-metas) 'noun-plural "") #:noun-singular (hash-ref (current-metas) 'noun-singular ""))))) Index: keyword-index.rkt ================================================================== --- keyword-index.rkt +++ keyword-index.rkt @@ -106,11 +106,11 @@ ◊string-append{ SELECT entry, subentry, a.rowid, "◊web-root" || k.page || "#" || html_anchor AS href, title_plain FROM index_entries k INNER JOIN articles a ON a.page = k.page ORDER BY entry COLLATE NOCASE ASC, subentry COLLATE NOCASE ASC;}) - (query-rows cache-conn q)) + (query-rows (cache-conn) q)) ;; Convert a list of vectors from the cache DB into a list of the form: ;; ((FIRST-LETTER (entries ...)) ...) ;; The method relies on the records being pre-sorted by the SQL query. (define (group-entries records) Index: rss-feed.rkt ================================================================== --- rss-feed.rkt +++ rss-feed.rkt @@ -64,11 +64,11 @@ `content_html` as `entry_contents` FROM `notes` WHERE (NOT (`conceal` LIKE "%all%")) AND (NOT (`conceal` LIKE "%feed%"))) ORDER BY `published` DESC LIMIT ~a --- ) - (query-rows cache-conn (format select feed-item-limit))) + (query-rows (cache-conn) (format select feed-item-limit))) (define (vector->rss-item vec) (match-define (vector path title published updated author contents) vec) (define entry-url (string-append feed-site-url web-root path))