Compare commits

..

1 Commits

Author SHA1 Message Date
de61e45637 feat: html 캐시
Some checks failed
build / build (push) Failing after 1m33s
2026-03-27 18:45:46 -06:00
4 changed files with 42 additions and 52 deletions

View File

@@ -12,10 +12,13 @@
(defonce ^:dynamic *use-db-cache?* true) (defonce ^:dynamic *use-db-cache?* true)
(defn- ds [] (def db-path (-> cfg/*cfg* ::publisher/org-roam-db-path
(sql/get-datasource fs/expand-home str))
{:dbtype "sqlite"
:dbname (-> cfg/*cfg* ::publisher/org-roam-db-path str)})) (def db {:dbtype "sqlite"
:dbname db-path})
(def ds (sql/get-datasource db))
;;; Elisp sexp (de)serialisation ;;; Elisp sexp (de)serialisation
@@ -35,7 +38,7 @@
(defrecord Node [id cache]) (defrecord Node [id cache])
(defn- uuid-exists? [uuid] (defn- uuid-exists? [uuid]
(sql/execute-one! (ds) (sql/execute-one! ds
["select 1 from nodes where id = ? limit 1" ["select 1 from nodes where id = ? limit 1"
(-> uuid str elisp/print)])) (-> uuid str elisp/print)]))
@@ -56,7 +59,7 @@
node :org-file node :org-file
(fn [node] (fn [node]
(when-some [r (sql/execute-one! (when-some [r (sql/execute-one!
(ds) ds
["select file from nodes where id = ?" ["select file from nodes where id = ?"
(-> node :id str elisp/print)])] (-> node :id str elisp/print)])]
(-> r :nodes/file elisp/read-string))))) (-> r :nodes/file elisp/read-string)))))
@@ -87,7 +90,7 @@
(fetch-with-cache (fetch-with-cache
node :title node :title
#(do (println "fetch") #(do (println "fetch")
(sql/execute-one! (ds) ["select title from nodes where id = ?" (sql/execute-one! ds ["select title from nodes where id = ?"
(elisp/print (:id %))])))) (elisp/print (:id %))]))))
@@ -97,7 +100,7 @@
(fetch-with-cache (fetch-with-cache
node :level node :level
#(-> (sql/execute-one! #(-> (sql/execute-one!
(ds) ["select level from nodes where id = ?" ds ["select level from nodes where id = ?"
(print-id %)]) (print-id %)])
:nodes/level))) :nodes/level)))
@@ -108,7 +111,7 @@
(fetch-with-cache (fetch-with-cache
node :file node :file
#(-> (sql/execute-one! #(-> (sql/execute-one!
(ds) ["select file from nodes where id = ?" ds ["select file from nodes where id = ?"
(print-id %)]) (print-id %)])
:nodes/file :nodes/file
elisp/read-string))) elisp/read-string)))
@@ -117,7 +120,7 @@
(fetch-with-cache (fetch-with-cache
node :properties node :properties
#(-> (sql/execute-one! #(-> (sql/execute-one!
(ds) ["select properties from nodes where id = ?" ds ["select properties from nodes where id = ?"
(print-id %)]) (print-id %)])
:nodes/properties :nodes/properties
elisp/read-alist))) elisp/read-alist)))
@@ -133,7 +136,7 @@
"Returns a collection of maps {:id …, :title …}." "Returns a collection of maps {:id …, :title …}."
[node] [node]
(for [{id :nodes/id, title :nodes/title} (for [{id :nodes/id, title :nodes/title}
(sql/execute! (ds) ["select distinct nodes.id, nodes.title from links (sql/execute! ds ["select distinct nodes.id, nodes.title from links
inner join nodes inner join nodes
on nodes.id = links.source on nodes.id = links.source
where links.dest = ?" where links.dest = ?"
@@ -153,9 +156,9 @@
(-> uuid parse-uuid get-node graph-visible?)) (-> uuid parse-uuid get-node graph-visible?))
(defn get-graph [] (defn get-graph []
(let [nodes (sql/execute! (ds) ["select id, title from nodes"]) (let [nodes (sql/execute! ds ["select id, title from nodes"])
links (sql/execute! links (sql/execute!
(ds) ds
["select n1.id as source, nodes.id as target from ["select n1.id as source, nodes.id as target from
((nodes as n1) join links on n1.id = links.source) ((nodes as n1) join links on n1.id = links.source)
join (nodes as n2) on links.dest = nodes.id join (nodes as n2) on links.dest = nodes.id

View File

@@ -1,6 +0,0 @@
:PROPERTIES:
:ID: ebc5ea84-77ab-4d60-9b13-ef9160b11d1f
:END:
#+title: deertopia.net!!!!!!!!
homeee

View File

@@ -8,7 +8,8 @@
[net.deertopia.doerg :as-alias doerg] [net.deertopia.doerg :as-alias doerg]
[net.deertopia.publisher.roam :as roam])) [net.deertopia.publisher.roam :as roam]))
(defn config-fixture [f] (t/use-fixtures
:once (fn [f]
(binding [doerg-cfg/*cfg* (binding [doerg-cfg/*cfg*
(doerg-cfg/read-config (doerg-cfg/read-config
::doerg/config doerg-cfg/sources ::doerg/config doerg-cfg/sources
@@ -17,10 +18,7 @@
(doerg-cfg/read-config (doerg-cfg/read-config
::publisher/config publisher-cfg/sources ::publisher/config publisher-cfg/sources
:profile :test)] :profile :test)]
(f))) (f))))
(t/use-fixtures
:once config-fixture)
(defn with-server [f] (defn with-server [f]
(let [was-already-running? (= :running (sut/status))] (let [was-already-running? (= :running (sut/status))]
@@ -40,26 +38,21 @@
(with-server (with-server
(fn [] (fn []
(t/is (= :running (sut/status))) (t/is (= :running (sut/status)))
;; 테스트 데이터베이스를 아직 안 준비한다. (t/is (->> (format "http://localhost:%d"
#_(t/is (->> (format "http://localhost:%d"
(::publisher/port publisher-cfg/*cfg*)) (::publisher/port publisher-cfg/*cfg*))
slurp slurp
string?))))) string?)))))
(comment
;; 테스트 데이터베이스를 아직 안 준비한다.
(t/deftest get-nonexistent-node (t/deftest get-nonexistent-node
(let [slug "3Lxvxnb0QrivoU3DX-l_5w"] (let [slug "3Lxvxnb0QrivoU3DX-l_5w"]
(assert (nil? (roam/make-node slug))) (assert (nil? (roam/make-node slug)))
(t/is (= 404 (t/is (= 404
(-> (str "/n/" slug) (-> (str "/n/" slug)
get-sut :status)))))) get-sut :status)))))
(comment
;; 테스트 데이터베이스를 아직 안 준비한다.
(t/deftest get-homepage (t/deftest get-homepage
(let [resp (-> (str "/n/" sut/homepage-slug) (let [resp (-> (str "/n/" sut/homepage-slug)
get-sut)] get-sut)]
(t/is (= 200 (:status resp))) (t/is (= 200 (:status resp)))
(t/is (= (-> "/" get-sut :body) (t/is (= (-> "/" get-sut :body)
(-> resp :body)))))) (-> resp :body)))))