mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
be1389420b
* SQL format checking, 1. * SQL format checking, 2. * SQL format checking, 3. * SQL format checking, 4. * SQL format checking, 5. * Running pg_format * Getting rid of comment. * Upping pg_format version. * Using git ls-files for sql format check. * Fixing sql lints. * Addressing PR comments.
74 lines
1.4 KiB
SQL
74 lines
1.4 KiB
SQL
CREATE VIEW user_mention_mview AS
|
|
with all_comment AS (
|
|
SELECT
|
|
ca.*
|
|
FROM
|
|
comment_aggregates_mview ca
|
|
)
|
|
SELECT
|
|
ac.id,
|
|
um.id AS user_mention_id,
|
|
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,
|
|
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,
|
|
um.recipient_id
|
|
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
|
|
ac.id,
|
|
um.id AS user_mention_id,
|
|
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,
|
|
NULL AS user_id,
|
|
NULL AS my_vote,
|
|
NULL AS saved,
|
|
um.recipient_id
|
|
FROM
|
|
all_comment ac
|
|
LEFT JOIN user_mention um ON um.comment_id = ac.id;
|
|
|