Skip to content

Commit 03e659c

Browse files
kawasimaclaude
andcommitted
Fix Copilot review: restore find-thread comments, batch evict
- threads.clj: restore find-thread with full comment pull (used by bot and curation). Add find-thread-meta for metadata-only queries. - thread.clj: thread-resource uses find-thread-meta; readonly resource keeps find-thread with comments for bot/curation consumers. - cache.clj: single-swap evict-expired! using reduce instead of per-key swap! to reduce contention and overhead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fb6a516 commit 03e659c

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/clj/back_channeling/boundary/threads.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
(pull [datomic id])
88
(find-threads [datomic board-name q])
99
(find-thread [datomic thread-id])
10+
(find-thread-meta [datomic thread-id])
1011
(find-watchers [datomic thread-id])
1112

1213
(add-watcher [datomic thread-id identity])
@@ -57,6 +58,17 @@
5758
vec))
5859

5960
(find-thread [{:keys [connection]} thread-id]
61+
(-> (d/pull (d/db connection)
62+
'[:*
63+
{:thread/comments
64+
[:*
65+
{:comment/format [:db/ident]}
66+
{:comment/posted-by [:user/name :user/email]}]}]
67+
thread-id)
68+
(update-in [:thread/comments]
69+
(partial map-indexed #(assoc %2 :comment/no (inc %1))))))
70+
71+
(find-thread-meta [{:keys [connection]} thread-id]
6072
(d/pull (d/db connection)
6173
'[:db/id :thread/title :thread/since :thread/last-updated :thread/public?
6274
{:thread/watchers [:user/name :user/email]}]

src/clj/back_channeling/database/cache.clj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
(defrecord Boundary [cache scheduler])
77

88
(defn- evict-expired!
9-
"Force eviction of expired entries by touching every key via has?."
9+
"Force eviction of all expired entries in a single atomic swap."
1010
[cache-atom]
11-
(doseq [k (keys @cache-atom)]
12-
(swap! cache-atom #(if (cache/has? % k) % (cache/evict % k)))))
11+
(swap! cache-atom
12+
(fn [c]
13+
(reduce (fn [acc k]
14+
(if (cache/has? acc k) acc (cache/evict acc k)))
15+
c (keys c)))))
1316

1417
(defmethod ig/init-key :back-channeling.database/cache [_ {:keys [ttl] :or {ttl (* 30 60 1000)}}]
1518
(let [cache-atom (atom (cache/ttl-cache-factory {} :ttl ttl))

src/clj/back_channeling/resource/thread.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@
6161
:handle-created (fn [_]
6262
{:status "ok"})
6363
:handle-ok (fn [_]
64-
(threads/find-thread datomic thread-id))))
64+
(threads/find-thread-meta datomic thread-id))))
6565

66+
;; Readonly resource returns full thread with comments (used by bot, curation)
6667
(defn thread-readonly-resource [{:keys [datomic]} thread-id]
6768
(liberator/resource base-resource
6869
:allowed-methods [:get]

0 commit comments

Comments
 (0)