Skip to content
Snippets Groups Projects
Commit 66ef5243 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 60c4ff77
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
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__account_id = find_account_id( _observer, True );
RETURN QUERY
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
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -49,14 +45,13 @@ BEGIN
hp.community_title,
hp.role_id,
hp.is_pinned,
hp.curator_payout_value,
hp.is_muted
hp.curator_payout_value
FROM
hive_posts_view hp
JOIN hive_subscriptions hs ON hp.community_id = hs.community_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 hp.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp.id < __post_id ) AND muted_accounts.muted_account_id IS NULL
WHERE hs.account_id = __account_id AND hp.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp.id < __post_id )
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
ORDER BY hp.id DESC
LIMIT _limit;
END
......@@ -78,11 +73,7 @@ BEGIN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__account_id = find_account_id( _observer, True );
RETURN QUERY
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
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -123,9 +114,9 @@ BEGIN
FROM
hive_posts_view hp
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
AND ( __post_id = 0 OR hp.sc_hot < __hot_limit OR ( hp.sc_hot = __hot_limit AND hp.id < __post_id ) ) AND muted_accounts.muted_account_id IS NULL
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)
ORDER BY hp.sc_hot DESC, hp.id DESC
LIMIT _limit;
END
......@@ -147,11 +138,7 @@ BEGIN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__account_id = find_account_id( _observer, True );
RETURN QUERY
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
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -203,8 +190,7 @@ BEGIN
LIMIT _limit
) as payout
JOIN hive_posts_view hp ON hp.id = payout.id
LEFT JOIN muted_accounts ON hp.author_id = muted_accounts.muted_account_id
WHERE muted_accounts.muted_account_id IS NULL
WHERE hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit;
END
......@@ -228,11 +214,7 @@ BEGIN
END IF;
__account_id = find_account_id( _observer, True );
__head_block_time = head_block_time();
RETURN QUERY
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
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -273,10 +255,9 @@ BEGIN
FROM
hive_posts_view hp
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'
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 muted_accounts.muted_account_id IS NULL
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC
LIMIT _limit;
END
......@@ -298,11 +279,7 @@ BEGIN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__account_id = find_account_id( _observer, True );
RETURN QUERY
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
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -343,10 +320,9 @@ BEGIN
FROM
hive_posts_view hp
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
AND ( __post_id = 0 OR hp.promoted < __promoted_limit OR ( hp.promoted = __promoted_limit AND hp.id < __post_id ) )
AND muted_accounts.muted_account_id IS NULL
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
ORDER BY hp.promoted DESC, hp.id DESC
LIMIT _limit;
END
......@@ -368,11 +344,7 @@ BEGIN
IF __post_id <> 0 THEN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
RETURN QUERY
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
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -422,12 +394,12 @@ BEGIN
WHERE
ha.name = _observer 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 hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
ORDER BY hp1.sc_trend DESC, hp1.id DESC
LIMIT _limit
) trending
JOIN hive_posts_view hp ON trending.id = hp.id
LEFT JOIN muted_accounts ON hp.author_id = muted_accounts.muted_account_id
WHERE muted_accounts.muted_account_id IS NULL
ORDER BY trending.sc_trend DESC, trending.id DESC
LIMIT _limit;
END
......@@ -449,11 +421,7 @@ BEGIN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__account_id = find_account_id( _observer, True );
RETURN QUERY
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
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
......@@ -495,10 +463,9 @@ BEGIN
hive_posts_view hp
JOIN hive_subscriptions hs ON hp.community_id = hs.community_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
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 muted_accounts.muted_account_id IS NULL
AND hp.author NOT IN (SELECT muted FROM muted_accounts_view WHERE observer = _observer)
ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC
LIMIT _limit;
END
......
......@@ -35,7 +35,8 @@ CREATE TYPE bridge_api_post AS (
community_title VARCHAR,
role_id SMALLINT,
is_pinned BOOLEAN,
curator_payout_value VARCHAR
curator_payout_value VARCHAR,
is_muted BOOLEAN
);
DROP TYPE IF EXISTS bridge_api_post_reblogs CASCADE;
......
......@@ -357,3 +357,20 @@ CREATE INDEX IF NOT EXISTS hive_posts_promoted_id_idx ON hive_posts (promoted, i
WHERE NOT is_paidout AND counter_deleted = 0
;
DROP VIEW IF EXISTS muted_accounts_view;
CREATE OR REPLACE VIEW muted_accounts_view AS
(
SELECT observer_accounts.name AS observer, following_accounts.name AS muted
FROM hive_follows JOIN hive_accounts following_accounts ON hive_follows.following = following_accounts.id
JOIN hive_accounts observer_accounts ON hive_follows.follower = observer_accounts.id
WHERE hive_follows.state = 2
UNION
SELECT observer_accounts.name AS observer, following_accounts.name AS muted
FROM hive_follows hive_follows_direct JOIN hive_follows hive_follows_indirect ON hive_follows_direct.following = hive_follows_indirect.follower
JOIN hive_accounts following_accounts ON hive_follows_indirect.following = following_accounts.id
JOIN hive_accounts observer_accounts ON hive_follows_direct.follower = observer_accounts.id
WHERE hive_follows_direct.follow_muted AND hive_follows_indirect.state = 2
);
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