feat: Implement lazy loading for comments via a new "Load Comments" button and simplify notification queries by exclusively using reference_id for comment joins.

This commit is contained in:
x
2026-01-25 03:57:14 +01:00
parent d903ce8b98
commit f958bbff52

View File

@@ -8,15 +8,10 @@ export default (router, tpl) => {
try {
const notifications = await db`
SELECT n.id, n.type, n.item_id, n.comment_id, n.reference_id, n.created_at, n.is_read,
SELECT n.id, n.type, n.item_id, n.reference_id, n.created_at, n.is_read,
u.user as from_user, u.id as from_user_id
FROM notifications n
-- Join on reference_id (which is comment_id) or comment_id.
-- Since we just set both, let's join on comment_id if present, fallback to reference_id?
-- The join was: JOIN comments c ON n.comment_id = c.id
-- If comment_id was null before my fix, this join would fail for old notifs.
-- Let's assume we use reference_id as the ID for now.
JOIN comments c ON (n.comment_id = c.id OR n.reference_id = c.id)
JOIN comments c ON n.reference_id = c.id
JOIN "user" u ON c.user_id = u.id
WHERE n.user_id = ${req.session.id} AND n.is_read = false
ORDER BY n.created_at DESC