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

[JES] Try to apply muting at the SQL level instead for more efficiency. This...

[JES] Try to apply muting at the SQL level instead for more efficiency. This only covers the bridge methods at the moment
parent 13868a13
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!370Jsalyers muting at sql level
...@@ -9,7 +9,11 @@ DECLARE ...@@ -9,7 +9,11 @@ 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 SELECT 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
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -45,17 +49,19 @@ BEGIN ...@@ -45,17 +49,19 @@ 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
JOIN hive_accounts_view ha ON ha.id = hp.author_id JOIN hive_accounts_view ha ON ha.id = hp.author_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 ) 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
ORDER BY hp.id DESC ORDER BY hp.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql VOLATILE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_hot_for_observer_communities; DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_hot_for_observer_communities;
CREATE FUNCTION bridge_get_ranked_post_by_hot_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT ) CREATE FUNCTION bridge_get_ranked_post_by_hot_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
...@@ -72,7 +78,11 @@ BEGIN ...@@ -72,7 +78,11 @@ BEGIN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id; SELECT hp.sc_hot INTO __hot_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 SELECT 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
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -108,17 +118,19 @@ BEGIN ...@@ -108,17 +118,19 @@ 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
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 muted_accounts.muted_account_id IS NULL
ORDER BY hp.sc_hot DESC, hp.id DESC ORDER BY hp.sc_hot DESC, hp.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql VOLATILE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_payout_comments_for_observer_communities; DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_payout_comments_for_observer_communities;
CREATE FUNCTION bridge_get_ranked_post_by_payout_comments_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT ) CREATE FUNCTION bridge_get_ranked_post_by_payout_comments_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
...@@ -135,7 +147,11 @@ BEGIN ...@@ -135,7 +147,11 @@ 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 SELECT 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
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -171,7 +187,8 @@ BEGIN ...@@ -171,7 +187,8 @@ 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
( (
SELECT SELECT
...@@ -186,11 +203,13 @@ BEGIN ...@@ -186,11 +203,13 @@ BEGIN
LIMIT _limit LIMIT _limit
) as payout ) as payout
JOIN hive_posts_view hp ON hp.id = payout.id 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
ORDER BY payout.all_payout DESC, payout.id DESC ORDER BY payout.all_payout DESC, payout.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql VOLATILE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_payout_for_observer_communities; DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_payout_for_observer_communities;
CREATE FUNCTION bridge_get_ranked_post_by_payout_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT ) CREATE FUNCTION bridge_get_ranked_post_by_payout_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
...@@ -209,7 +228,11 @@ BEGIN ...@@ -209,7 +228,11 @@ 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 SELECT 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
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -245,17 +268,20 @@ BEGIN ...@@ -245,17 +268,20 @@ 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
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 muted_accounts.muted_account_id IS NULL
ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql VOLATILE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_promoted_for_observer_communities; DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_promoted_for_observer_communities;
CREATE FUNCTION bridge_get_ranked_post_by_promoted_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT ) CREATE FUNCTION bridge_get_ranked_post_by_promoted_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
...@@ -272,7 +298,11 @@ BEGIN ...@@ -272,7 +298,11 @@ 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 SELECT 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
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -308,17 +338,20 @@ BEGIN ...@@ -308,17 +338,20 @@ 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
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 muted_accounts.muted_account_id IS NULL
ORDER BY hp.promoted DESC, hp.id DESC ORDER BY hp.promoted DESC, hp.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql VOLATILE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_trends_for_observer_communities; DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_trends_for_observer_communities;
CREATE OR REPLACE FUNCTION bridge_get_ranked_post_by_trends_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT ) CREATE OR REPLACE FUNCTION bridge_get_ranked_post_by_trends_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
...@@ -327,13 +360,19 @@ AS ...@@ -327,13 +360,19 @@ AS
$function$ $function$
DECLARE DECLARE
__post_id INT; __post_id INT;
__account_id INT;
__trending_limit FLOAT := 0; __trending_limit FLOAT := 0;
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 );
IF __post_id <> 0 THEN IF __post_id <> 0 THEN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id; SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF; END IF;
RETURN QUERY SELECT 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
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -369,7 +408,8 @@ BEGIN ...@@ -369,7 +408,8 @@ 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
( (
SELECT SELECT
...@@ -386,11 +426,13 @@ BEGIN ...@@ -386,11 +426,13 @@ BEGIN
LIMIT _limit LIMIT _limit
) trending ) trending
JOIN hive_posts_view hp ON trending.id = hp.id 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 ORDER BY trending.sc_trend DESC, trending.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql VOLATILE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_muted_for_observer_communities; DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_muted_for_observer_communities;
CREATE FUNCTION bridge_get_ranked_post_by_muted_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT ) CREATE FUNCTION bridge_get_ranked_post_by_muted_for_observer_communities( in _observer VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
...@@ -407,7 +449,11 @@ BEGIN ...@@ -407,7 +449,11 @@ 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 SELECT 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
hp.id, hp.id,
hp.author, hp.author,
hp.parent_author, hp.parent_author,
...@@ -443,15 +489,18 @@ BEGIN ...@@ -443,15 +489,18 @@ 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
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 muted_accounts.muted_account_id IS NULL
ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql VOLATILE;
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