fix(postgres): get_thread uses recursive CTE — fetches all nested replies not just direct ones
Some checks failed
lint / lint (push) Has been cancelled
test / integration (push) Has been cancelled
test / unit (push) Has been cancelled
lint / lint (pull_request) Failing after 9m18s
test / unit (pull_request) Successful in 16m9s
test / integration (pull_request) Failing after 17m5s

This commit is contained in:
2026-05-14 17:56:03 +02:00
parent 255ff549a4
commit 5c9acdecc1

View File

@@ -116,9 +116,19 @@ impl ThoughtRepository for PgThoughtRepository {
} }
async fn get_thread(&self, id: &ThoughtId) -> Result<Vec<Thought>, DomainError> { async fn get_thread(&self, id: &ThoughtId) -> Result<Vec<Thought>, DomainError> {
sqlx::query_as::<_, ThoughtRow>(&format!( // Recursive CTE: fetches the root thought and all nested replies at any depth.
"{THOUGHT_SELECT} WHERE id=$1 OR in_reply_to_id=$1 ORDER BY created_at ASC" sqlx::query_as::<_, ThoughtRow>(
)) "WITH RECURSIVE thread AS (
SELECT id,user_id,content,in_reply_to_id,in_reply_to_url,ap_id,
visibility,content_warning,sensitive,local,created_at,updated_at
FROM thoughts WHERE id = $1
UNION ALL
SELECT t.id,t.user_id,t.content,t.in_reply_to_id,t.in_reply_to_url,t.ap_id,
t.visibility,t.content_warning,t.sensitive,t.local,t.created_at,t.updated_at
FROM thoughts t JOIN thread ON t.in_reply_to_id = thread.id
)
SELECT * FROM thread ORDER BY created_at ASC",
)
.bind(id.as_uuid()) .bind(id.as_uuid())
.fetch_all(&self.pool) .fetch_all(&self.pool)
.await .await