Fix: forenkle channels-query, fjern ugyldig factoids.title referanse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
vegard 2026-03-16 02:29:13 +01:00
parent 0d8521855f
commit a6ca0f602d

View file

@ -10,21 +10,12 @@ export const load: PageServerLoad = async ({ locals }) => {
c.id,
c.name,
c.config,
n.workspace_id,
p.name AS parent_name,
pn.node_type AS parent_name,
(SELECT count(*)::int FROM messages m WHERE m.channel_id = c.id) AS message_count,
(SELECT max(m.created_at) FROM messages m WHERE m.channel_id = c.id) AS last_message_at
FROM channels c
JOIN nodes n ON n.id = c.id
LEFT JOIN nodes pn ON pn.id = c.parent_id
LEFT JOIN (
SELECT id, COALESCE(
(SELECT name FROM channels WHERE id = pn2.id),
(SELECT title FROM factoids WHERE id = pn2.id),
pn2.node_type
) AS name
FROM nodes pn2
) p ON p.id = c.parent_id
WHERE n.workspace_id = ${locals.workspace.id}
ORDER BY c.name
`;