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:
'hive_posts_author_id_created_at_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_idx',
'hive_posts_promoted_id_idx',
......
......@@ -139,7 +139,7 @@ def build_metadata():
sa.Index('hive_posts_root_id_id_idx', 'root_id','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_idx', 'payout'),
......
......@@ -9,52 +9,64 @@ DECLARE
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__account_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
hp.author_rep,
hp.root_title,
hp.beneficiaries,
hp.max_accepted_payout,
hp.percent_hbd,
hp.url,
hp.permlink,
hp.parent_permlink_or_category,
hp.title,
hp.body,
hp.category,
hp.depth,
hp.promoted,
hp.payout,
hp.pending_payout,
hp.payout_at,
hp.is_paidout,
hp.children,
hp.votes,
hp.created_at,
hp.updated_at,
hp.rshares,
hp.abs_rshares,
hp.json,
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
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
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 (NOT EXISTS (SELECT 1 FROM muted_accounts_by_id_view WHERE observer_id = __account_id AND muted_id = hp.author_id))
ORDER BY hp.id DESC
LIMIT _limit;
RETURN QUERY
with post_ids as (select posts.id
from (select community_id
from hive_subscriptions
where account_id = __account_id) communities
cross join lateral (select hive_posts.id
from hive_posts
join hive_accounts on (hive_posts.author_id = hive_accounts.id)
where hive_posts.community_id = communities.community_id
and hive_posts.depth = 0
and hive_posts.counter_deleted = 0
and (__post_id = 0 OR hive_posts.id < __post_id)
and hive_accounts.reputation > '-464800000000'::bigint
order by id desc
limit _limit) posts
order by id desc
limit _limit)
SELECT
hp.id,
hp.author,
hp.parent_author,
hp.author_rep,
hp.root_title,
hp.beneficiaries,
hp.max_accepted_payout,
hp.percent_hbd,
hp.url,
hp.permlink,
hp.parent_permlink_or_category,
hp.title,
hp.body,
hp.category,
hp.depth,
hp.promoted,
hp.payout,
hp.pending_payout,
hp.payout_at,
hp.is_paidout,
hp.children,
hp.votes,
hp.created_at,
hp.updated_at,
hp.rshares,
hp.abs_rshares,
hp.json,
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
$function$
language plpgsql STABLE;
......
......@@ -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_voter_id_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_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_posts_community_id_id_idx ON hive_posts (community_id, id DESC);
DO
$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