Skip to content
Snippets Groups Projects
Commit a76b951e authored by Jason Salyers's avatar Jason Salyers
Browse files

[JES] Create a view for getting the muted accounts. Not In/Not Exists/Left...

[JES] Create a view for getting the muted accounts. Not In/Not Exists/Left Join all have extremely similar processing times. Went with Not In for readibility
parent 951d1833
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!370Jsalyers muting at sql level
...@@ -9,11 +9,7 @@ DECLARE ...@@ -9,11 +9,7 @@ DECLARE
BEGIN BEGIN
__post_id = find_comment_id( _author, _permlink, True ); __post_id = find_comment_id( _author, _permlink, True );
__account_id = find_account_id( _observer, True ); __account_id = find_account_id( _observer, True );
RETURN QUERY RETURN QUERY SELECT
WITH muted_accounts AS (SELECT following as muted_account_id from hive_follows WHERE follower = __account_id AND state = 2 UNION
SELECT hive_follows_indirect.following as muted_account_id FROM hive_follows hive_follows_direct JOIN hive_follows hive_follows_indirect ON hive_follows_direct.following = hive_follows_indirect.follower
WHERE hive_follows_direct.follower = __account_id AND hive_follows_direct.follow_muted AND hive_follows_indirect.state = 2)
SELECT
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -49,8 +45,7 @@ BEGIN ...@@ -49,8 +45,7 @@ BEGIN
hp.community_title, hp.community_title,
hp.role_id, hp.role_id,
hp.is_pinned, hp.is_pinned,
hp.curator_payout_value, hp.curator_payout_value
hp.is_muted
FROM FROM
hive_posts_view hp hive_posts_view hp
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
...@@ -119,7 +114,6 @@ BEGIN ...@@ -119,7 +114,6 @@ BEGIN
FROM FROM
hive_posts_view hp hive_posts_view hp
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
LEFT JOIN muted_accounts ON hp.author_id = muted_accounts.muted_account_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.depth = 0 WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.depth = 0
AND ( __post_id = 0 OR hp.sc_hot < __hot_limit OR ( hp.sc_hot = __hot_limit AND hp.id < __post_id ) ) AND ( __post_id = 0 OR hp.sc_hot < __hot_limit OR ( hp.sc_hot = __hot_limit AND hp.id < __post_id ) )
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer) AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
...@@ -144,11 +138,7 @@ BEGIN ...@@ -144,11 +138,7 @@ BEGIN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id; SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF; END IF;
__account_id = find_account_id( _observer, True ); __account_id = find_account_id( _observer, True );
RETURN QUERY RETURN QUERY SELECT
WITH muted_accounts AS (SELECT following as muted_account_id from hive_follows WHERE follower = __account_id AND state = 2 UNION
SELECT hive_follows_indirect.following as muted_account_id FROM hive_follows hive_follows_direct JOIN hive_follows hive_follows_indirect ON hive_follows_direct.following = hive_follows_indirect.follower
WHERE hive_follows_direct.follower = __account_id AND hive_follows_direct.follow_muted AND hive_follows_indirect.state = 2)
SELECT
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -224,11 +214,7 @@ BEGIN ...@@ -224,11 +214,7 @@ BEGIN
END IF; END IF;
__account_id = find_account_id( _observer, True ); __account_id = find_account_id( _observer, True );
__head_block_time = head_block_time(); __head_block_time = head_block_time();
RETURN QUERY RETURN QUERY SELECT
WITH muted_accounts AS (SELECT following as muted_account_id from hive_follows WHERE follower = __account_id AND state = 2 UNION
SELECT hive_follows_indirect.following as muted_account_id FROM hive_follows hive_follows_direct JOIN hive_follows hive_follows_indirect ON hive_follows_direct.following = hive_follows_indirect.follower
WHERE hive_follows_direct.follower = __account_id AND hive_follows_direct.follow_muted AND hive_follows_indirect.state = 2)
SELECT
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -269,7 +255,6 @@ BEGIN ...@@ -269,7 +255,6 @@ BEGIN
FROM FROM
hive_posts_view hp hive_posts_view hp
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
LEFT JOIN muted_accounts ON hp.author_id = muted_accounts.muted_account_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours' WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours'
AND ( __post_id = 0 OR ( hp.payout + hp.pending_payout ) < __payout_limit OR ( ( hp.payout + hp.pending_payout ) = __payout_limit AND hp.id < __post_id ) ) AND ( __post_id = 0 OR ( hp.payout + hp.pending_payout ) < __payout_limit OR ( ( hp.payout + hp.pending_payout ) = __payout_limit AND hp.id < __post_id ) )
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer) AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
...@@ -294,11 +279,7 @@ BEGIN ...@@ -294,11 +279,7 @@ BEGIN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id; SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF; END IF;
__account_id = find_account_id( _observer, True ); __account_id = find_account_id( _observer, True );
RETURN QUERY RETURN QUERY SELECT
WITH muted_accounts AS (SELECT following as muted_account_id from hive_follows WHERE follower = __account_id AND state = 2 UNION
SELECT hive_follows_indirect.following as muted_account_id FROM hive_follows hive_follows_direct JOIN hive_follows hive_follows_indirect ON hive_follows_direct.following = hive_follows_indirect.follower
WHERE hive_follows_direct.follower = __account_id AND hive_follows_direct.follow_muted AND hive_follows_indirect.state = 2)
SELECT
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -339,7 +320,6 @@ BEGIN ...@@ -339,7 +320,6 @@ BEGIN
FROM FROM
hive_posts_view hp hive_posts_view hp
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
LEFT JOIN muted_accounts ON hp.author_id = muted_accounts.muted_account_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.promoted > 0 WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND hp.promoted > 0
AND ( __post_id = 0 OR hp.promoted < __promoted_limit OR ( hp.promoted = __promoted_limit AND hp.id < __post_id ) ) AND ( __post_id = 0 OR hp.promoted < __promoted_limit OR ( hp.promoted = __promoted_limit AND hp.id < __post_id ) )
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer) AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
...@@ -414,6 +394,7 @@ BEGIN ...@@ -414,6 +394,7 @@ BEGIN
WHERE WHERE
hs.account_id = __account_id AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0 hs.account_id = __account_id AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0
AND ( __post_id = 0 OR hp1.sc_trend < __trending_limit OR ( hp1.sc_trend = __trending_limit AND hp1.id < __post_id ) ) AND ( __post_id = 0 OR hp1.sc_trend < __trending_limit OR ( hp1.sc_trend = __trending_limit AND hp1.id < __post_id ) )
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
ORDER BY hp1.sc_trend DESC, hp1.id DESC ORDER BY hp1.sc_trend DESC, hp1.id DESC
LIMIT _limit LIMIT _limit
) trending ) trending
...@@ -440,11 +421,7 @@ BEGIN ...@@ -440,11 +421,7 @@ BEGIN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id; SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF; END IF;
__account_id = find_account_id( _observer, True ); __account_id = find_account_id( _observer, True );
RETURN QUERY RETURN QUERY SELECT
WITH muted_accounts AS (SELECT following as muted_account_id from hive_follows WHERE follower = __account_id AND state = 2 UNION
SELECT hive_follows_indirect.following as muted_account_id FROM hive_follows hive_follows_direct JOIN hive_follows hive_follows_indirect ON hive_follows_direct.following = hive_follows_indirect.follower
WHERE hive_follows_direct.follower = __account_id AND hive_follows_direct.follow_muted AND hive_follows_indirect.state = 2)
SELECT
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -486,7 +463,6 @@ BEGIN ...@@ -486,7 +463,6 @@ BEGIN
hive_posts_view hp hive_posts_view hp
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id JOIN hive_subscriptions hs ON hp.community_id = hs.community_id
JOIN hive_accounts_view ha ON ha.id = hp.author_id JOIN hive_accounts_view ha ON ha.id = hp.author_id
LEFT JOIN muted_accounts ON hp.author_id = muted_accounts.muted_account_id
WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND ha.is_grayed AND ( hp.payout + hp.pending_payout ) > 0 WHERE hs.account_id = __account_id AND NOT hp.is_paidout AND ha.is_grayed AND ( hp.payout + hp.pending_payout ) > 0
AND ( __post_id = 0 OR ( hp.payout + hp.pending_payout ) < __payout_limit OR ( ( hp.payout + hp.pending_payout ) = __payout_limit AND hp.id < __post_id ) ) AND ( __post_id = 0 OR ( hp.payout + hp.pending_payout ) < __payout_limit OR ( ( hp.payout + hp.pending_payout ) = __payout_limit AND hp.id < __post_id ) )
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer) AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
......
...@@ -35,7 +35,8 @@ CREATE TYPE bridge_api_post AS ( ...@@ -35,7 +35,8 @@ CREATE TYPE bridge_api_post AS (
community_title VARCHAR, community_title VARCHAR,
role_id SMALLINT, role_id SMALLINT,
is_pinned BOOLEAN, is_pinned BOOLEAN,
curator_payout_value VARCHAR curator_payout_value VARCHAR,
is_muted BOOLEAN
); );
DROP TYPE IF EXISTS bridge_api_post_reblogs CASCADE; DROP TYPE IF EXISTS bridge_api_post_reblogs CASCADE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment