Skip to content
Snippets Groups Projects
Commit 243f0ca6 authored by Bartek Wrona's avatar Bartek Wrona
Browse files

Merge branch 'km_isssue_127' into 'develop'

Eliminated more references to hive_posts_view

See merge request !470
parents ebc75a89 a725fd22
No related branches found
No related tags found
1 merge request!470Eliminated more references to hive_posts_view
CREATE OR REPLACE FUNCTION get_post_view_by_id(_id hive_posts.id%TYPE) RETURNS SETOF hive_posts_view
CREATE TYPE get_post_view_by_id_return_t AS(
id integer,
community_id integer,
root_id integer,
parent_id integer,
author character varying(16) COLLATE pg_catalog."C",
active timestamp without time zone,
author_rewards bigint,
author_id integer,
permlink character varying(255) COLLATE pg_catalog."C",
title character varying(512),
body text,
img_url character varying(1024),
preview character varying(1024),
category character varying(255) COLLATE pg_catalog."C",
category_id integer,
depth smallint,
promoted numeric(10,3),
payout numeric(10,3),
pending_payout numeric(10,3),
payout_at timestamp without time zone,
last_payout_at timestamp without time zone,
cashout_time timestamp without time zone,
is_paidout boolean,
children integer,
votes integer,
active_votes integer,
created_at timestamp without time zone,
updated_at timestamp without time zone,
rshares numeric,
abs_rshares numeric,
total_votes bigint,
net_votes bigint,
json text,
author_rep bigint,
is_hidden boolean,
is_grayed boolean,
total_vote_weight numeric,
parent_author character varying(16) COLLATE pg_catalog."C",
parent_author_id integer,
parent_permlink_or_category character varying(255) COLLATE pg_catalog."C",
curator_payout_value character varying(30),
root_author character varying(16) COLLATE pg_catalog."C",
root_permlink character varying(255) COLLATE pg_catalog."C",
root_category character varying(255) COLLATE pg_catalog."C",
max_accepted_payout character varying(30),
percent_hbd integer,
allow_replies boolean,
allow_votes boolean,
allow_curation_rewards boolean,
beneficiaries json,
url text COLLATE pg_catalog."C",
root_title character varying(512),
sc_trend real,
sc_hot real,
is_pinned boolean,
is_muted boolean,
is_nsfw boolean,
is_valid boolean,
role_title character varying(140),
role_id smallint,
community_title character varying(32),
community_name character varying(16) COLLATE pg_catalog."C",
block_num integer
);
CREATE OR REPLACE FUNCTION get_post_view_by_id(_id hive_posts.id%TYPE) RETURNS SETOF get_post_view_by_id_return_t
AS $function$
BEGIN
RETURN QUERY
......
......@@ -4,95 +4,3 @@ CREATE OR REPLACE VIEW live_posts_view AS SELECT * FROM live_posts_comments_view
CREATE OR REPLACE VIEW live_comments_view AS SELECT * FROM live_posts_comments_view WHERE depth != 0;
DROP VIEW IF EXISTS public.hive_posts_view;
CREATE OR REPLACE VIEW public.hive_posts_view
AS
SELECT hp.id,
hp.community_id,
hp.root_id,
hp.parent_id,
ha_a.name AS author,
hp.active,
hp.author_rewards,
hp.author_id,
hpd_p.permlink,
hpd.title,
hpd.body,
hpd.img_url,
hpd.preview,
hcd.category,
hp.category_id,
hp.depth,
hp.promoted,
hp.payout,
hp.pending_payout,
hp.payout_at,
hp.last_payout_at,
hp.cashout_time,
hp.is_paidout,
hp.children,
0 AS votes,
0 AS active_votes,
hp.created_at,
hp.updated_at,
hp.vote_rshares AS rshares,
hp.abs_rshares AS abs_rshares,
hp.total_votes AS total_votes,
hp.net_votes as net_votes,
hpd.json,
ha_a.reputation AS author_rep,
hp.is_hidden,
ha_a.is_grayed,
hp.total_vote_weight,
ha_pp.name AS parent_author,
ha_pp.id AS parent_author_id,
( CASE hp.depth > 0
WHEN True THEN hpd_pp.permlink
ELSE hcd.category
END ) AS parent_permlink_or_category,
hp.curator_payout_value,
ha_rp.name AS root_author,
hpd_rp.permlink AS root_permlink,
rcd.category as root_category,
hp.max_accepted_payout,
hp.percent_hbd,
True AS allow_replies,
hp.allow_votes,
hp.allow_curation_rewards,
hp.beneficiaries,
CONCAT('/', rcd.category, '/@', ha_rp.name, '/', hpd_rp.permlink,
CASE (rp.id)
WHEN hp.id THEN ''
ELSE CONCAT('#@', ha_a.name, '/', hpd_p.permlink)
END
) AS url,
rpd.title AS root_title,
hp.sc_trend,
hp.sc_hot,
hp.is_pinned,
hp.is_muted,
hp.is_nsfw,
hp.is_valid,
hr.title AS role_title,
hr.role_id AS role_id,
hc.title AS community_title,
hc.name AS community_name,
hp.block_num
FROM hive_posts hp
JOIN hive_posts pp ON pp.id = hp.parent_id
JOIN hive_posts rp ON rp.id = hp.root_id
JOIN hive_accounts_view ha_a ON ha_a.id = hp.author_id
JOIN hive_permlink_data hpd_p ON hpd_p.id = hp.permlink_id
JOIN hive_post_data hpd ON hpd.id = hp.id
JOIN hive_accounts ha_pp ON ha_pp.id = pp.author_id
JOIN hive_permlink_data hpd_pp ON hpd_pp.id = pp.permlink_id
JOIN hive_accounts ha_rp ON ha_rp.id = rp.author_id
JOIN hive_permlink_data hpd_rp ON hpd_rp.id = rp.permlink_id
JOIN hive_post_data rpd ON rpd.id = rp.id
JOIN hive_category_data hcd ON hcd.id = hp.category_id
JOIN hive_category_data rcd ON rcd.id = rp.category_id
LEFT JOIN hive_communities hc ON hp.community_id = hc.id
LEFT JOIN hive_roles hr ON hp.author_id = hr.account_id AND hp.community_id = hr.community_id
WHERE hp.counter_deleted = 0
;
......@@ -33,9 +33,9 @@ FROM
) rank
;
DROP FUNCTION IF EXISTS public.calculate_notify_vote_score(_payout hive_posts.payout%TYPE, _abs_rshares hive_posts_view.abs_rshares%TYPE, _rshares hive_votes.rshares%TYPE) CASCADE
DROP FUNCTION IF EXISTS public.calculate_notify_vote_score(_payout hive_posts.payout%TYPE, _abs_rshares hive_posts.abs_rshares%TYPE, _rshares hive_votes.rshares%TYPE) CASCADE
;
CREATE OR REPLACE FUNCTION public.calculate_notify_vote_score(_payout hive_posts.payout%TYPE, _abs_rshares hive_posts_view.abs_rshares%TYPE, _rshares hive_votes.rshares%TYPE)
CREATE OR REPLACE FUNCTION public.calculate_notify_vote_score(_payout hive_posts.payout%TYPE, _abs_rshares hive_posts.abs_rshares%TYPE, _rshares hive_votes.rshares%TYPE)
RETURNS INT
LANGUAGE 'sql'
IMMUTABLE
......@@ -64,7 +64,7 @@ LANGUAGE plpgsql IMMUTABLE
DROP FUNCTION IF EXISTS public.calculate_value_of_vote_on_post CASCADE;
CREATE OR REPLACE FUNCTION public.calculate_value_of_vote_on_post(
_post_payout hive_posts.payout%TYPE
, _post_rshares hive_posts_view.rshares%TYPE
, _post_rshares hive_posts.vote_rshares%TYPE
, _vote_rshares hive_votes.rshares%TYPE)
RETURNS FLOAT
LANGUAGE 'sql'
......
......@@ -469,3 +469,7 @@ ALTER TABLE hive_notification_cache
DROP INDEX IF EXISTS hive_posts_parent_id_counter_deleted_id_idx;
CREATE INDEX IF NOT EXISTS hive_posts_parent_id_id_idx ON hive_posts (parent_id, id DESC) where counter_deleted = 0;
--- Drop this view as it was eliminated.
DROP VIEW IF EXISTS hive_posts_view CASCADE;
......@@ -98,53 +98,60 @@ async def find_comments(context, comments: list):
db = context['db']
SQL_TEMPLATE = """
SELECT
pv.id,
pv.community_id,
pv.author,
pv.permlink,
pv.title,
pv.body,
pv.category,
pv.depth,
pv.promoted,
pv.payout,
pv.last_payout_at,
pv.cashout_time,
pv.is_paidout,
pv.children,
pv.votes,
pv.created_at,
pv.updated_at,
pv.rshares,
pv.json,
pv.is_hidden,
pv.is_grayed,
pv.total_votes,
pv.net_votes,
pv.total_vote_weight,
pv.parent_permlink_or_category,
pv.curator_payout_value,
pv.root_author,
pv.root_permlink,
pv.max_accepted_payout,
pv.percent_hbd,
pv.allow_replies,
pv.allow_votes,
pv.allow_curation_rewards,
pv.beneficiaries,
pv.url,
pv.root_title,
pv.abs_rshares,
pv.active,
pv.author_rewards,
pv.parent_author
FROM (
SELECT
hp.id,
hp.community_id,
hp.author,
hp.permlink,
hp.title,
hp.body,
hp.category,
hp.depth,
hp.promoted,
hp.payout,
hp.last_payout_at,
hp.cashout_time,
hp.is_paidout,
hp.children,
hp.votes,
hp.created_at,
hp.updated_at,
hp.rshares,
hp.json,
hp.is_hidden,
hp.is_grayed,
hp.total_votes,
hp.net_votes,
hp.total_vote_weight,
hp.parent_author,
hp.parent_permlink_or_category,
hp.curator_payout_value,
hp.root_author,
hp.root_permlink,
hp.max_accepted_payout,
hp.percent_hbd,
hp.allow_replies,
hp.allow_votes,
hp.allow_curation_rewards,
hp.beneficiaries,
hp.url,
hp.root_title,
hp.abs_rshares,
hp.active,
hp.author_rewards
hp.id
FROM
hive_posts_view hp
JOIN (VALUES {}) AS t (author, permlink, number) ON hp.author = t.author AND hp.permlink = t.permlink
live_posts_comments_view hp
JOIN hive_accounts_view ha_a ON ha_a.id = hp.author_id
JOIN hive_permlink_data hpd_p ON hpd_p.id = hp.permlink_id
JOIN (VALUES {}) AS t (author, permlink, number) ON ha_a.name = t.author AND hpd_p.permlink = t.permlink
WHERE
NOT hp.is_muted
NOT hp.is_muted
ORDER BY t.number
) ds,
LATERAL get_post_view_by_id (ds.id) pv
"""
idx = 0
......@@ -238,4 +245,3 @@ async def list_votes(context, start: list, limit: int = 1000, order: str = None)
sql = "SELECT * FROM list_votes_by_comment_voter(:voter,:author,:permlink,:limit)"
rows = await db.query_all(sql, voter=start_voter, author=author, permlink=permlink, limit=limit)
return { 'votes': api_vote_info(rows, VotesPresentation.DatabaseApi) }
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