2023-08-02 16:44:51 +00:00
|
|
|
CREATE VIEW user_mention_mview AS
|
|
|
|
with all_comment AS (
|
|
|
|
SELECT
|
|
|
|
ca.*
|
|
|
|
FROM
|
|
|
|
comment_aggregates_mview ca
|
2020-01-29 03:07:17 +00:00
|
|
|
)
|
2023-08-02 16:44:51 +00:00
|
|
|
SELECT
|
2020-01-29 03:07:17 +00:00
|
|
|
ac.id,
|
2023-08-02 16:44:51 +00:00
|
|
|
um.id AS user_mention_id,
|
2020-01-29 03:07:17 +00:00
|
|
|
ac.creator_id,
|
|
|
|
ac.post_id,
|
|
|
|
ac.parent_id,
|
|
|
|
ac.content,
|
|
|
|
ac.removed,
|
|
|
|
um.read,
|
|
|
|
ac.published,
|
|
|
|
ac.updated,
|
|
|
|
ac.deleted,
|
|
|
|
ac.community_id,
|
|
|
|
ac.banned,
|
|
|
|
ac.banned_from_community,
|
|
|
|
ac.creator_name,
|
|
|
|
ac.creator_avatar,
|
|
|
|
ac.score,
|
|
|
|
ac.upvotes,
|
|
|
|
ac.downvotes,
|
2023-08-02 16:44:51 +00:00
|
|
|
u.id AS user_id,
|
|
|
|
coalesce(cl.score, 0) AS my_vote,
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
cs.id::bool
|
|
|
|
FROM
|
|
|
|
comment_saved cs
|
|
|
|
WHERE
|
|
|
|
u.id = cs.user_id
|
|
|
|
AND cs.comment_id = ac.id) AS saved,
|
2020-01-29 03:07:17 +00:00
|
|
|
um.recipient_id
|
2023-08-02 16:44:51 +00:00
|
|
|
FROM
|
|
|
|
user_ u
|
|
|
|
CROSS JOIN all_comment ac
|
|
|
|
LEFT JOIN comment_like cl ON u.id = cl.user_id
|
|
|
|
AND ac.id = cl.comment_id
|
|
|
|
LEFT JOIN user_mention um ON um.comment_id = ac.id
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2020-01-29 03:07:17 +00:00
|
|
|
ac.id,
|
2023-08-02 16:44:51 +00:00
|
|
|
um.id AS user_mention_id,
|
2020-01-29 03:07:17 +00:00
|
|
|
ac.creator_id,
|
|
|
|
ac.post_id,
|
|
|
|
ac.parent_id,
|
|
|
|
ac.content,
|
|
|
|
ac.removed,
|
|
|
|
um.read,
|
|
|
|
ac.published,
|
|
|
|
ac.updated,
|
|
|
|
ac.deleted,
|
|
|
|
ac.community_id,
|
|
|
|
ac.banned,
|
|
|
|
ac.banned_from_community,
|
|
|
|
ac.creator_name,
|
|
|
|
ac.creator_avatar,
|
|
|
|
ac.score,
|
|
|
|
ac.upvotes,
|
|
|
|
ac.downvotes,
|
2023-08-02 16:44:51 +00:00
|
|
|
NULL AS user_id,
|
|
|
|
NULL AS my_vote,
|
|
|
|
NULL AS saved,
|
2020-01-29 03:07:17 +00:00
|
|
|
um.recipient_id
|
2023-08-02 16:44:51 +00:00
|
|
|
FROM
|
|
|
|
all_comment ac
|
|
|
|
LEFT JOIN user_mention um ON um.comment_id = ac.id;
|
2020-01-29 03:07:17 +00:00
|
|
|
|