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:
@@ -8,15 +8,10 @@ export default (router, tpl) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const notifications = await db`
|
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
|
u.user as from_user, u.id as from_user_id
|
||||||
FROM notifications n
|
FROM notifications n
|
||||||
-- Join on reference_id (which is comment_id) or comment_id.
|
JOIN comments c ON n.reference_id = c.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 "user" u ON c.user_id = u.id
|
JOIN "user" u ON c.user_id = u.id
|
||||||
WHERE n.user_id = ${req.session.id} AND n.is_read = false
|
WHERE n.user_id = ${req.session.id} AND n.is_read = false
|
||||||
ORDER BY n.created_at DESC
|
ORDER BY n.created_at DESC
|
||||||
|
|||||||
Reference in New Issue
Block a user