Compare commits

..

1 Commits

Author SHA1 Message Date
9cc0def4d5 feat: html 캐시
All checks were successful
build / build (push) Successful in 4s
2026-03-27 19:42:51 -06:00
4 changed files with 52 additions and 42 deletions

View File

@@ -12,13 +12,10 @@
(defonce ^:dynamic *use-db-cache?* true) (defonce ^:dynamic *use-db-cache?* true)
(def db-path (-> cfg/*cfg* ::publisher/org-roam-db-path (defn- ds []
fs/expand-home str)) (sql/get-datasource
{:dbtype "sqlite"
(def db {:dbtype "sqlite" :dbname (-> cfg/*cfg* ::publisher/org-roam-db-path str)}))
:dbname db-path})
(def ds (sql/get-datasource db))
;;; Elisp sexp (de)serialisation ;;; Elisp sexp (de)serialisation
@@ -38,7 +35,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)]))
@@ -59,7 +56,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)))))
@@ -90,7 +87,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 %))]))))
@@ -100,7 +97,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)))
@@ -111,7 +108,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)))
@@ -120,7 +117,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)))
@@ -136,7 +133,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 = ?"
@@ -156,9 +153,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

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

View File

@@ -8,8 +8,7 @@
[net.deertopia.doerg :as-alias doerg] [net.deertopia.doerg :as-alias doerg]
[net.deertopia.publisher.roam :as roam])) [net.deertopia.publisher.roam :as roam]))
(t/use-fixtures (defn config-fixture [f]
: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
@@ -18,7 +17,10 @@
(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))]
@@ -38,21 +40,26 @@
(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))))))