diff --git a/hive/db/schema.py b/hive/db/schema.py index 8eedc803d85fd9d300cd4bf4609e1de023d048f9..741524beae79324fa04687f7f5e6cd01a28b6a75 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -558,6 +558,7 @@ def setup(db): "hive_votes_view.sql", "hive_muted_accounts_view.sql", "hive_muted_accounts_by_id_view.sql", + "hive_blacklisted_accounts_by_observer_view.sql", "hive_post_operations.sql", "head_block_time.sql", "update_feed_cache.sql", diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql index f605a5bc8a0cd8bb7e5f0716b08865d4a2d41993..9377ba5d454acfcd5c13251e95397828244843f0 100644 --- a/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql +++ b/hive/db/sql_scripts/bridge_get_account_posts_by_blog.sql @@ -60,7 +60,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp JOIN ( diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql index f701d0fbd49f953281a109f5d92941939db613d2..3a0ffeb49a81ce26c0a70c5e53cfefe37946d248 100644 --- a/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql +++ b/hive/db/sql_scripts/bridge_get_account_posts_by_comments.sql @@ -47,7 +47,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM ( SELECT hp1.id diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql index 5b54be03b61ea043bde671ff47a820f0ab35daa0..5106cb3791cb187580a6732c8ac96f362d2b6ae2 100644 --- a/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql +++ b/hive/db/sql_scripts/bridge_get_account_posts_by_payout.sql @@ -51,7 +51,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp WHERE diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql index 8993c684b9caa883be20c8958f4874907e0e9503..b0be3c7d361aa01ecb355ba77f1842b66ff3d67b 100644 --- a/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql +++ b/hive/db/sql_scripts/bridge_get_account_posts_by_posts.sql @@ -47,7 +47,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp WHERE diff --git a/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql b/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql index f011f69903bd937d1db8c9ebdc203f06cb192b0f..d23fee279f25a66d0f7fea5835adfcf084e02c6a 100644 --- a/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql +++ b/hive/db/sql_scripts/bridge_get_account_posts_by_replies.sql @@ -57,7 +57,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM ( SELECT diff --git a/hive/db/sql_scripts/bridge_get_discussion.sql b/hive/db/sql_scripts/bridge_get_discussion.sql index e4450cfd0d8a88d681503a5b53e76ccd02ed3316..6644f6c89ef25467164c078e5e0159f34a2d1f49 100644 --- a/hive/db/sql_scripts/bridge_get_discussion.sql +++ b/hive/db/sql_scripts/bridge_get_discussion.sql @@ -54,24 +54,25 @@ BEGIN hpv.is_pinned, hpv.curator_payout_value, hpv.is_muted, - hpv.parent_id + hpv.parent_id, + ds.source FROM ( WITH RECURSIVE child_posts (id, parent_id) AS ( - SELECT hp.id, hp.parent_id - FROM hive_posts hp + SELECT hp.id, hp.parent_id, blacklisted_by_observer_view.source as source + FROM hive_posts hp left outer join blacklisted_by_observer_view on (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp.author_id) WHERE hp.id = __post_id AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp.author_id)) UNION ALL - SELECT children.id, children.parent_id - FROM hive_posts children + SELECT children.id, children.parent_id, blacklisted_by_observer_view.source as source + FROM hive_posts children left outer join blacklisted_by_observer_view on (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = children.author_id) JOIN child_posts ON children.parent_id = child_posts.id JOIN hive_accounts ON children.author_id = hive_accounts.id WHERE children.counter_deleted = 0 AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = children.author_id)) ) - SELECT hp2.id + SELECT hp2.id, cp.source FROM hive_posts hp2 JOIN child_posts cp ON cp.id = hp2.id ORDER BY hp2.id diff --git a/hive/db/sql_scripts/bridge_get_post.sql b/hive/db/sql_scripts/bridge_get_post.sql index 16b46f6332fbae003d06d9f1fc61514cafc0a79c..3ad4667a14e61bb07f0b50c171160d9a109b625c 100644 --- a/hive/db/sql_scripts/bridge_get_post.sql +++ b/hive/db/sql_scripts/bridge_get_post.sql @@ -45,7 +45,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp WHERE diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql index 426d7b798bb1b7bdc2a3765016c3a07c3276d732..95fb2deb8867da8bf4b11c1c9dc6c25474248eb6 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql @@ -46,13 +46,15 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + created.source FROM ( SELECT - hp1.id + hp1.id, blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_accounts_view ha ON hp1.author_id = ha.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.counter_deleted = 0 AND hp1.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp1.id < __post_id ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) ORDER BY hp1.id DESC @@ -117,14 +119,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + hot.source FROM ( SELECT hp1.id - , hp1.sc_hot as hot + , hp1.sc_hot as hot, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0 AND ( __post_id = 0 OR hp1.sc_hot < __hot_limit OR ( hp1.sc_hot = __hot_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -146,8 +151,10 @@ $function$ DECLARE __post_id INT; __payout_limit hive_posts.payout%TYPE; + __observer_id INT; BEGIN __post_id = find_comment_id( _author, _permlink, True ); + __observer_id = find_account_id(_observer, True); IF __post_id <> 0 THEN SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id; END IF; @@ -188,15 +195,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_accounts_view ha ON hp1.author_id = ha.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND ha.is_grayed AND ( hp1.payout + hp1.pending_payout ) > 0 AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC @@ -261,14 +271,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth > 0 AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -336,14 +349,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND ( ( NOT _bridge_api AND hp1.depth = 0 ) OR ( _bridge_api AND hp1.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours' ) ) AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) @@ -410,14 +426,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + promoted.source FROM ( SELECT hp1.id - , hp1.promoted as promoted + , hp1.promoted as promoted, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.promoted > 0 AND ( __post_id = 0 OR hp1.promoted < __promoted_limit OR ( hp1.promoted = __promoted_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -483,14 +502,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + trends.source FROM ( SELECT hp1.id - , hp1.sc_trend as trend + , hp1.sc_trend as trend, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE 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 (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql index 4658fcf76b1abbf0f8c84720a8646d32efb854af..d29491f3a420e5f67709b5b130f8a7a51b083ea1 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql @@ -44,10 +44,12 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + blacklisted_by_observer_view.source FROM hive_posts_view hp JOIN hive_communities hc ON hc.id = hp.community_id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp.author_id) WHERE hc.name = _community AND hp.is_pinned AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp.author_id)) ORDER BY hp.id DESC @@ -108,15 +110,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + trends.source FROM ( SELECT hp1.id - , hp1.sc_trend as trend + , hp1.sc_trend as trend, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_communities hc ON hp1.community_id = hc.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0 AND ( NOT _bridge_api OR NOT hp1.is_pinned ) -- concatenated with bridge_get_ranked_post_pinned_for_community when called for bridge_api AND ( __post_id = 0 OR hp1.sc_trend < __trending_limit OR ( hp1.sc_trend = __trending_limit AND hp1.id < __post_id ) ) @@ -183,15 +188,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + promoted.source FROM ( SELECT hp1.id - , hp1.promoted as promoted + , hp1.promoted as promoted, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_communities hc ON hp1.community_id = hc.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.promoted > 0 AND ( __post_id = 0 OR hp1.promoted < __promoted_limit OR ( hp1.promoted = __promoted_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -259,15 +267,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_communities hc ON hp1.community_id = hc.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours' AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -333,15 +344,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_communities hc ON hp1.community_id = hc.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth > 0 AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -363,11 +377,13 @@ $function$ DECLARE __post_id INT; __payout_limit hive_posts.payout%TYPE; + __observer_id INT; BEGIN __post_id = find_comment_id( _author, _permlink, True ); IF __post_id <> 0 THEN SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id; END IF; + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -405,16 +421,19 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_communities hc ON hp1.community_id = hc.id JOIN hive_accounts_view ha ON hp1.author_id = ha.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND ha.is_grayed AND ( hp1.payout + hp1.pending_payout ) > 0 AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC @@ -479,15 +498,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + hot.source FROM ( SELECT hp1.id - , hp1.sc_hot as hot + , hp1.sc_hot as hot, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_communities hc ON hp1.community_id = hc.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0 AND ( __post_id = 0 OR hp1.sc_hot < __hot_limit OR ( hp1.sc_hot = __hot_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -549,14 +571,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + created.source FROM ( SELECT - hp1.id + hp1.id, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_communities hc ON hp1.community_id = hc.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hc.name = _community AND hp1.counter_deleted = 0 AND hp1.depth = 0 AND ( NOT _bridge_api OR NOT hp1.is_pinned ) -- concatenated with bridge_get_ranked_post_pinned_for_community when called for bridge_api AND ( __post_id = 0 OR hp1.id < __post_id ) diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql index 395eabf22c4da304a21bec1e96ba82ea50017f12..4d72902fc2af949d315a140247aaadc9037983e2 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql @@ -6,6 +6,7 @@ $function$ DECLARE __post_id INT; __account_id INT; + __subscription_count INT; BEGIN __post_id = find_comment_id( _author, _permlink, True ); __account_id = find_account_id( _observer, True ); @@ -64,9 +65,11 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + blacklisted_by_observer_view.source from post_ids join hive_posts_view hp using (id) + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __account_id AND blacklisted_by_observer_view.blacklisted_id = hp.author_id) order by id desc; END $function$ @@ -124,10 +127,12 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + blacklisted_by_observer_view.source FROM hive_posts_view hp JOIN hive_subscriptions hs ON hp.community_id = hs.community_id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __account_id AND blacklisted_by_observer_view.blacklisted_id = hp.author_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 (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id)) @@ -189,15 +194,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.blacklist_source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as blacklist_source FROM hive_posts hp1 JOIN hive_subscriptions hs ON hp1.community_id = hs.community_id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __account_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE 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.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp1.author_id)) @@ -265,10 +273,12 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + blacklisted_by_observer_view.source FROM hive_posts_view hp JOIN hive_subscriptions hs ON hp.community_id = hs.community_id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __account_id AND blacklisted_by_observer_view.blacklisted_id = hp.author_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 (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id)) @@ -330,10 +340,12 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + blacklisted_by_observer_view.source FROM hive_posts_view hp JOIN hive_subscriptions hs ON hp.community_id = hs.community_id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __account_id AND blacklisted_by_observer_view.blacklisted_id = hp.author_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 (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id)) @@ -396,15 +408,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + trending.source FROM ( SELECT hp1.id - , hp1.sc_trend + , hp1.sc_trend, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_subscriptions hs ON hp1.community_id = hs.community_id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __account_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE 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 ) ) @@ -471,11 +486,13 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + blacklisted_by_observer_view.source 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 OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __account_id AND blacklisted_by_observer_view.blacklisted_id = hp.author_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 ) ) ORDER BY ( hp.payout + hp.pending_payout ) DESC, hp.id DESC diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql index 7c40c81a7c81ddaeadf6b0a6876bfd7f185770b2..d9bddcd4de97544e6febd07348464ee206ecc4b4 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql @@ -10,7 +10,7 @@ DECLARE BEGIN __post_id = find_comment_id( _author, _permlink, True ); __hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True )); - __observer_id = find_account_id( _observer, True ); + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -48,14 +48,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + created.source FROM ( SELECT - hp1.id + hp1.id, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_accounts_view ha ON hp1.author_id = ha.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.tags_ids @> __hive_tag AND hp1.counter_deleted = 0 AND hp1.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp1.id < __post_id ) --ORDER BY hp1.id + 0 DESC -- this workaround helped the query to better choose indexes, but after some time it started to significally slow down AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -85,7 +88,7 @@ BEGIN SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id; END IF; __hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True )); - __observer_id = find_account_id( _observer, True ); + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -123,14 +126,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + hot.source FROM ( SELECT hp1.id - , hp1.sc_hot as hot + , hp1.sc_hot as hot, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.tags_ids @> __hive_tag AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0 AND ( __post_id = 0 OR hp1.sc_hot < __hot_limit OR ( hp1.sc_hot = __hot_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -153,12 +159,14 @@ DECLARE __post_id INT; __payout_limit hive_posts.payout%TYPE; __hive_tag INT[]; + __observer_id INT; BEGIN __post_id = find_comment_id( _author, _permlink, True ); IF __post_id <> 0 THEN SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id; END IF; __hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True ) ); + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -196,15 +204,18 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 JOIN hive_accounts_view ha ON hp1.author_id = ha.id + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.tags_ids @> __hive_tag AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND ha.is_grayed AND ( hp1.payout + hp1.pending_payout ) > 0 AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC @@ -233,7 +244,7 @@ BEGIN SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id; END IF; __hive_category = find_category_id( _category, True ); - __observer_id = find_account_id( _observer, True ); + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -271,14 +282,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.category_id = __hive_category AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth > 0 AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -310,7 +324,7 @@ BEGIN END IF; __hive_category = find_category_id( _category, True ); __head_block_time = head_block_time(); - __observer_id = find_account_id( _observer, True ); + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -348,14 +362,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + payout.source FROM ( SELECT hp1.id - , ( hp1.payout + hp1.pending_payout ) as all_payout + , ( hp1.payout + hp1.pending_payout ) as all_payout, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.category_id = __hive_category AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND ( ( NOT _bridge_api AND hp1.depth = 0 ) OR ( _bridge_api AND hp1.payout_at BETWEEN __head_block_time + interval '12 hours' AND __head_block_time + interval '36 hours' ) ) AND ( __post_id = 0 OR ( hp1.payout + hp1.pending_payout ) < __payout_limit OR ( ( hp1.payout + hp1.pending_payout ) = __payout_limit AND hp1.id < __post_id ) ) @@ -386,7 +403,7 @@ BEGIN SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id; END IF; __hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True ) ); - __observer_id = find_account_id( _observer, True ); + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -424,14 +441,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + promoted.source FROM ( SELECT hp1.id - , hp1.promoted as promoted + , hp1.promoted as promoted, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.tags_ids @> __hive_tag AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.promoted > 0 AND ( __post_id = 0 OR hp1.promoted < __promoted_limit OR ( hp1.promoted = __promoted_limit AND hp1.id < __post_id ) ) AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -461,7 +481,7 @@ BEGIN SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id; END IF; __hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True )); - __observer_id = find_account_id( _observer, True ); + __observer_id = find_account_id(_observer, True); RETURN QUERY SELECT hp.id, hp.author, @@ -499,14 +519,17 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + trends.source FROM ( SELECT hp1.id - , hp1.sc_trend as trend + , hp1.sc_trend as trend, + blacklisted_by_observer_view.source as source FROM hive_posts hp1 + LEFT OUTER JOIN blacklisted_by_observer_view ON (blacklisted_by_observer_view.observer_id = __observer_id AND blacklisted_by_observer_view.blacklisted_id = hp1.author_id) WHERE hp1.tags_ids @> __hive_tag 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 (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __observer_id AND muted_id = hp1.author_id)) @@ -514,6 +537,7 @@ BEGIN LIMIT _limit ) as trends JOIN hive_posts_view hp ON hp.id = trends.id + WHERE (CASE WHEN _observer IS NOT NULL THEN NOT EXISTS (SELECT 1 FROM muted_accounts_view WHERE observer = _observer AND muted = hp.author) ELSE true END) ORDER BY trends.trend DESC, trends.id DESC LIMIT _limit; END diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_type.sql b/hive/db/sql_scripts/bridge_get_ranked_post_type.sql index 7436418b5a1b763990c7f1bb14ce184e5dcb63d2..eee1ca6a0b762517a65b15567300ce0806b4a8fc 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_type.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_type.sql @@ -36,7 +36,8 @@ CREATE TYPE bridge_api_post AS ( role_id SMALLINT, is_pinned BOOLEAN, curator_payout_value VARCHAR, - is_muted BOOLEAN + is_muted BOOLEAN, + blacklists TEXT ); DROP TYPE IF EXISTS bridge_api_post_reblogs CASCADE; @@ -122,5 +123,6 @@ CREATE TYPE bridge_api_post_discussion AS ( is_pinned BOOLEAN, curator_payout_value VARCHAR, is_muted BOOLEAN, - parent_id INTEGER + parent_id INTEGER, + blacklists TEXT ); \ No newline at end of file diff --git a/hive/db/sql_scripts/condenser_get_by_account_comments.sql b/hive/db/sql_scripts/condenser_get_by_account_comments.sql index 62687cdf38f6fb1ffe9385a56377e3eeab0a50cb..e553dc4fe31683e5825022bdabd7142365d2ee67 100644 --- a/hive/db/sql_scripts/condenser_get_by_account_comments.sql +++ b/hive/db/sql_scripts/condenser_get_by_account_comments.sql @@ -53,7 +53,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp WHERE ( hp.author = _author ) AND ( ( __post_id = 0 ) OR ( hp.id <= __post_id ) ) AND hp.depth > 0 ORDER BY hp.id DESC diff --git a/hive/db/sql_scripts/condenser_get_by_blog.sql b/hive/db/sql_scripts/condenser_get_by_blog.sql index eda1cbdcb1370830c8947d4efa4fceb3fee50887..8939d1b56773efe73ffef7a6afa4395beeca2e2c 100644 --- a/hive/db/sql_scripts/condenser_get_by_blog.sql +++ b/hive/db/sql_scripts/condenser_get_by_blog.sql @@ -63,7 +63,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp JOIN hive_feed_cache hfc ON hp.id = hfc.post_id WHERE hfc.account_id = __account_id AND ( ( __post_id = 0 ) OR ( hfc.created_at <= __created_at ) ) diff --git a/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql b/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql index 588272fcbee7b061112e9d6ee46846814c78ddee..0be32a9b2c29a7ca87b931884614353ceb37b9e8 100644 --- a/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql +++ b/hive/db/sql_scripts/condenser_get_by_blog_without_reblog.sql @@ -53,7 +53,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp WHERE ( hp.author = _author ) AND ( ( __post_id = 0 ) OR ( hp.id <= __post_id ) ) AND hp.depth = 0 ORDER BY hp.id DESC diff --git a/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql b/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql index cc8ea3c823d7bd14e3a427d743fb6593e5ae61f9..8d71a91ee44a8d253d7b47fdd80396a704e174ee 100644 --- a/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql +++ b/hive/db/sql_scripts/condenser_get_discussions_by_comments.sql @@ -53,7 +53,8 @@ BEGIN hp.role_id, hp.is_pinned, hp.curator_payout_value, - hp.is_muted + hp.is_muted, + NULL FROM hive_posts_view hp WHERE hp.author = _author AND hp.depth > 0 AND ( ( __post_id = 0 ) OR ( hp.id <= __post_id ) ) diff --git a/hive/db/sql_scripts/db_upgrade.sh b/hive/db/sql_scripts/db_upgrade.sh index a6ec3b57f75ed5efa358204d58522c3daa5ba7af..29a2127b3b579e641d49bd438291d2eff4bd5b91 100755 --- a/hive/db/sql_scripts/db_upgrade.sh +++ b/hive/db/sql_scripts/db_upgrade.sh @@ -16,6 +16,7 @@ for sql in postgres_handle_view_changes.sql \ hive_votes_view.sql \ hive_muted_accounts_view.sql \ hive_muted_accounts_by_id_view.sql \ + hive_blacklisted_accounts_by_observer_view.sql \ hive_post_operations.sql \ head_block_time.sql \ update_feed_cache.sql \ diff --git a/hive/db/sql_scripts/hive_blacklisted_accounts_by_observer_view.sql b/hive/db/sql_scripts/hive_blacklisted_accounts_by_observer_view.sql new file mode 100644 index 0000000000000000000000000000000000000000..45a805d70abae0725e89a7f37cda62fbb2963609 --- /dev/null +++ b/hive/db/sql_scripts/hive_blacklisted_accounts_by_observer_view.sql @@ -0,0 +1,22 @@ +DROP VIEW IF EXISTS blacklisted_by_observer_view; +CREATE OR REPLACE VIEW blacklisted_by_observer_view AS +SELECT observer_accounts.id AS observer_id, + following_accounts.id AS blacklisted_id, + following_accounts.name AS blacklisted_name, + 'my blacklist'::text AS source + 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.blacklisted +UNION + SELECT observer_accounts.id AS observer_id, + following_accounts.id AS blacklisted_id, + following_accounts.name AS blacklisted_name, + string_agg(('blacklisted by '::text || (indirect_accounts.name)::text), ','::text) AS source + 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))) + JOIN hive_accounts indirect_accounts ON ((hive_follows_indirect.follower = indirect_accounts.id)) + WHERE (hive_follows_direct.follow_blacklists AND hive_follows_indirect.blacklisted) + GROUP BY observer_accounts.id, following_accounts.id; \ No newline at end of file diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py index a2bb35e6c6b89ff372d8b3499861836b4d835dc2..9735dd01fcda73f1c6695fd64260f2926b646fcc 100644 --- a/hive/server/bridge_api/methods.py +++ b/hive/server/bridge_api/methods.py @@ -58,16 +58,12 @@ async def get_post(context, author, permlink, observer=None): valid_account(observer, allow_empty=True) valid_permlink(permlink) - blacklisted_for_user = None - if observer: - blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context) - sql = "SELECT * FROM bridge_get_post( (:author)::VARCHAR, (:permlink)::VARCHAR )" result = await db.query_all(sql, author=author, permlink=permlink) post = _bridge_post_object(result[0]) post['active_votes'] = await find_votes_impl(db, author, permlink, VotesPresentation.BridgeApi) - post = append_statistics_to_post(post, result[0], False, blacklisted_for_user) + post = append_statistics_to_post(post, result[0], False) return post @return_error_info @@ -233,14 +229,11 @@ async def get_ranked_posts(context, sort:str, start_author:str='', start_permlin db = context['db'] async def process_query_results( sql_result ): - blacklisted_for_user = None - if observer: - blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context) posts = [] for row in sql_result: post = _bridge_post_object(row) post['active_votes'] = await find_votes_impl(db, row['author'], row['permlink'], VotesPresentation.BridgeApi) - post = append_statistics_to_post(post, row, row['is_pinned'], blacklisted_for_user) + post = append_statistics_to_post(post, row, row['is_pinned']) posts.append(post) return posts @@ -298,12 +291,6 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='', sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit ) posts = [] - blacklisted_for_user = None - if observer and account_posts: - # it looks like the opposite would make more sense, that is, to handle observer for 'blog', 'feed' and 'replies', - # since that's when posts can come from various authors, some blacklisted and some not, but original version - # ignored it (only) in those cases - blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context) for row in sql_result: post = _bridge_post_object(row) @@ -319,7 +306,7 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='', reblogged_by_list.sort() post['reblogged_by'] = reblogged_by_list - post = append_statistics_to_post(post, row, False if account_posts else row['is_pinned'], blacklisted_for_user) + post = append_statistics_to_post(post, row, False if account_posts else row['is_pinned']) posts.append(post) return posts diff --git a/hive/server/bridge_api/objects.py b/hive/server/bridge_api/objects.py index ab030fdaede9df4dfef99819a879811d44c126c6..fe52517f83320d2b8edb25df8b84cc23091baa2f 100644 --- a/hive/server/bridge_api/objects.py +++ b/hive/server/bridge_api/objects.py @@ -15,15 +15,14 @@ log = logging.getLogger(__name__) # pylint: disable=too-many-lines -def append_statistics_to_post(post, row, is_pinned, blacklisted_for_user={}): +def append_statistics_to_post(post, row, is_pinned): """ apply information such as blacklists and community names/roles to a given post """ post['blacklists'] = [] - if blacklisted_for_user and row['author'] in blacklisted_for_user: - blacklists = blacklisted_for_user[row['author']] - post['blacklists'].extend(blacklists[0]) - for mute_list in blacklists[1]: - post['blacklists'].append(mute_list + ' (mute list)') + if 'blacklists' in row and row['blacklists']: + split_lists = row['blacklists'].split(',') + for blacklist_source in split_lists: + post['blacklists'].append(blacklist_source) reputation = post['author_reputation'] if reputation < 1: post['blacklists'].append('reputation-0') diff --git a/hive/server/bridge_api/thread.py b/hive/server/bridge_api/thread.py index bafe0c7681aa26b7dd02ee4b22aa620300c77e3a..e184dc43c61146c60d5c5012031362faf2d12e85 100644 --- a/hive/server/bridge_api/thread.py +++ b/hive/server/bridge_api/thread.py @@ -21,10 +21,6 @@ async def get_discussion(context, author:str, permlink:str, observer:str=''): permlink = valid_permlink(permlink) observer = valid_account(observer, allow_empty=True) - blacklisted_for_user = None - if observer: - blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context) - sql = "SELECT * FROM bridge_get_discussion(:author,:permlink,:observer)" rows = await db.query_all(sql, author=author, permlink=permlink, observer=observer) if not rows or len(rows) == 0: @@ -33,7 +29,7 @@ async def get_discussion(context, author:str, permlink:str, observer:str=''): all_posts = {} root_post = _bridge_post_object(rows[0]) root_post['active_votes'] = await find_votes_impl(db, rows[0]['author'], rows[0]['permlink'], VotesPresentation.BridgeApi) - root_post = append_statistics_to_post(root_post, rows[0], False, blacklisted_for_user) + root_post = append_statistics_to_post(root_post, rows[0], False) root_post['replies'] = [] all_posts[root_id] = root_post @@ -46,7 +42,7 @@ async def get_discussion(context, author:str, permlink:str, observer:str=''): parent_to_children_id_map[parent_id].append(rows[index]['id']) post = _bridge_post_object(rows[index]) post['active_votes'] = await find_votes_impl(db, rows[index]['author'], rows[index]['permlink'], VotesPresentation.BridgeApi) - post = append_statistics_to_post(post, rows[index], False, blacklisted_for_user) + post = append_statistics_to_post(post, rows[index], False) post['replies'] = [] all_posts[post['post_id']] = post diff --git a/tests/tests_api b/tests/tests_api index 527f27b14bdf10c8a543b015dc3cad0afb0ada6c..7e65efd650e0d8bc41e194638121ce4b195ae29c 160000 --- a/tests/tests_api +++ b/tests/tests_api @@ -1 +1 @@ -Subproject commit 527f27b14bdf10c8a543b015dc3cad0afb0ada6c +Subproject commit 7e65efd650e0d8bc41e194638121ce4b195ae29c