Skip to content
Snippets Groups Projects
Commit 85da819a authored by Dan Notestein's avatar Dan Notestein
Browse files

Merge branch 'dn_fast_by_created_for_observer_communitites' into 'develop'

faster by created for observer communitites

See merge request !394
parents 022c075e 45ab5b3a
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!394faster by created for observer communitites
...@@ -107,7 +107,7 @@ class DbState: ...@@ -107,7 +107,7 @@ class DbState:
'hive_posts_author_id_created_at_idx', 'hive_posts_author_id_created_at_idx',
'hive_posts_root_id_id_idx', 'hive_posts_root_id_id_idx',
'hive_posts_community_id_idx', 'hive_posts_community_id_id_idx',
'hive_posts_payout_at_idx', 'hive_posts_payout_at_idx',
'hive_posts_payout_idx', 'hive_posts_payout_idx',
'hive_posts_promoted_id_idx', 'hive_posts_promoted_id_idx',
......
...@@ -139,7 +139,7 @@ def build_metadata(): ...@@ -139,7 +139,7 @@ def build_metadata():
sa.Index('hive_posts_root_id_id_idx', 'root_id','id'), sa.Index('hive_posts_root_id_id_idx', 'root_id','id'),
sa.Index('hive_posts_parent_id_idx', 'parent_id'), sa.Index('hive_posts_parent_id_idx', 'parent_id'),
sa.Index('hive_posts_community_id_idx', 'community_id'), sa.Index('hive_posts_community_id_id_idx', 'community_id', sa.text('id DESC')),
sa.Index('hive_posts_payout_at_idx', 'payout_at'), sa.Index('hive_posts_payout_at_idx', 'payout_at'),
sa.Index('hive_posts_payout_idx', 'payout'), sa.Index('hive_posts_payout_idx', 'payout'),
......
...@@ -9,52 +9,64 @@ DECLARE ...@@ -9,52 +9,64 @@ 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
hp.id, with post_ids as (select posts.id
hp.author, from (select community_id
hp.parent_author, from hive_subscriptions
hp.author_rep, where account_id = __account_id) communities
hp.root_title, cross join lateral (select hive_posts.id
hp.beneficiaries, from hive_posts
hp.max_accepted_payout, join hive_accounts on (hive_posts.author_id = hive_accounts.id)
hp.percent_hbd, where hive_posts.community_id = communities.community_id
hp.url, and hive_posts.depth = 0
hp.permlink, and hive_posts.counter_deleted = 0
hp.parent_permlink_or_category, and (__post_id = 0 OR hive_posts.id < __post_id)
hp.title, and hive_accounts.reputation > '-464800000000'::bigint
hp.body, order by id desc
hp.category, limit _limit) posts
hp.depth, order by id desc
hp.promoted, limit _limit)
hp.payout, SELECT
hp.pending_payout, hp.id,
hp.payout_at, hp.author,
hp.is_paidout, hp.parent_author,
hp.children, hp.author_rep,
hp.votes, hp.root_title,
hp.created_at, hp.beneficiaries,
hp.updated_at, hp.max_accepted_payout,
hp.rshares, hp.percent_hbd,
hp.abs_rshares, hp.url,
hp.json, hp.permlink,
hp.is_hidden, hp.parent_permlink_or_category,
hp.is_grayed, hp.title,
hp.total_votes, hp.body,
hp.sc_trend, hp.category,
hp.role_title, hp.depth,
hp.community_title, hp.promoted,
hp.role_id, hp.payout,
hp.is_pinned, hp.pending_payout,
hp.curator_payout_value, hp.payout_at,
hp.is_muted hp.is_paidout,
FROM hp.children,
hive_posts_view hp hp.votes,
JOIN hive_subscriptions hs ON hp.community_id = hs.community_id hp.created_at,
JOIN hive_accounts_view ha ON ha.id = hp.author_id hp.updated_at,
WHERE hs.account_id = __account_id AND hp.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp.id < __post_id ) hp.rshares,
AND (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id)) hp.abs_rshares,
ORDER BY hp.id DESC hp.json,
LIMIT _limit; hp.is_hidden,
hp.is_grayed,
hp.total_votes,
hp.sc_trend,
hp.role_title,
hp.community_title,
hp.role_id,
hp.is_pinned,
hp.curator_payout_value,
hp.is_muted
from post_ids
join hive_posts_view hp using (id)
order by id desc;
END END
$function$ $function$
language plpgsql STABLE; language plpgsql STABLE;
......
...@@ -73,10 +73,12 @@ drop index if exists hive_subscriptions_community_idx; ...@@ -73,10 +73,12 @@ drop index if exists hive_subscriptions_community_idx;
drop index if exists hive_votes_post_id_idx; drop index if exists hive_votes_post_id_idx;
drop index if exists hive_votes_voter_id_idx; drop index if exists hive_votes_voter_id_idx;
drop index if exists hive_votes_last_update_idx; drop index if exists hive_votes_last_update_idx;
drop index if exists hive_posts_community_id_idx;
CREATE INDEX IF NOT EXISTS hive_posts_cashout_time_id_idx ON hive_posts (cashout_time, id); CREATE INDEX IF NOT EXISTS hive_posts_cashout_time_id_idx ON hive_posts (cashout_time, id);
CREATE INDEX IF NOT EXISTS hive_posts_updated_at_idx ON hive_posts (updated_at DESC); CREATE INDEX IF NOT EXISTS hive_posts_updated_at_idx ON hive_posts (updated_at DESC);
CREATE INDEX IF NOT EXISTS hive_votes_block_num_idx ON hive_votes (block_num); CREATE INDEX IF NOT EXISTS hive_votes_block_num_idx ON hive_votes (block_num);
CREATE INDEX IF NOT EXISTS hive_posts_community_id_id_idx ON hive_posts (community_id, id DESC);
DO DO
$BODY$ $BODY$
......
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