Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/hivemind
1 result
Show changes
Commits on Source (30)
Showing
with 232 additions and 803 deletions
......@@ -94,6 +94,9 @@ class DbState:
to_locate = [
'hive_blocks_created_at_idx',
'hive_feed_cache_block_num_idx',
'hive_feed_cache_created_at_idx',
'hive_follows_ix5a', # (following, state, created_at, follower)
'hive_follows_ix5b', # (follower, state, created_at, following)
'hive_follows_block_num_idx',
......
......@@ -286,9 +286,12 @@ def build_metadata():
sa.Column('post_id', sa.Integer, nullable=False),
sa.Column('account_id', sa.Integer, nullable=False),
sa.Column('created_at', sa.DateTime, nullable=False),
sa.Column('block_num', sa.Integer, nullable=True),
sa.Column('block_num', sa.Integer, nullable=False),
sa.PrimaryKeyConstraint('account_id', 'post_id', name='hive_feed_cache_pk'),
sa.ForeignKeyConstraint(['block_num'], ['hive_blocks.num'], name='hive_feed_cache_fk1'),
sa.Index('hive_feed_cache_block_num_idx', 'block_num'),
sa.Index('hive_feed_cache_created_at_idx', 'created_at')
)
sa.Table(
......@@ -585,14 +588,10 @@ def setup(db):
"condenser_api_post_ex_type.sql",
"condenser_get_blog.sql",
"condenser_get_content.sql",
"condenser_get_discussions_by_created.sql",
"condenser_get_discussions_by_blog.sql",
"condenser_tags.sql",
"condenser_follows.sql",
"hot_and_trends.sql",
"condenser_get_discussions_by_trending.sql",
"condenser_get_discussions_by_hot.sql",
"condenser_get_discussions_by_promoted.sql",
"condenser_get_post_discussions_by_payout.sql",
"condenser_get_comment_discussions_by_payout.sql",
"update_hive_posts_children_count.sql",
"update_hive_posts_api_helper.sql",
"database_api_list_comments.sql",
......@@ -602,12 +601,9 @@ def setup(db):
"condenser_get_by_replies_to_account.sql",
"condenser_get_by_account_comments.sql",
"condenser_get_by_blog_without_reblog.sql",
"condenser_get_by_feed_with_reblog.sql",
"bridge_get_by_feed_with_reblog.sql",
"condenser_get_by_blog.sql",
"bridge_get_account_posts_by_blog.sql",
"condenser_get_follow_counts.sql",
"condenser_get_names_by_followers.sql",
"condenser_get_names_by_following.sql",
"condenser_get_names_by_reblogged.sql",
"condenser_get_discussions_by_comments.sql",
"condenser_get_account_reputations.sql"
......
......@@ -17,16 +17,12 @@ BEGIN
IF _permlink <> '' THEN
__post_id = find_comment_id( _author, _permlink, True );
__created_at =
(
SELECT created_at
FROM hive_feed_cache
WHERE account_id = __account_id
AND post_id = __post_id
);
SELECT hfc.created_at INTO __created_at
FROM hive_feed_cache hfc
WHERE hfc.account_id = __account_id AND hfc.post_id = __post_id;
END IF;
RETURN QUERY SELECT
RETURN QUERY SELECT -- bridge_get_account_posts_by_blog
hp.id,
hp.author,
hp.parent_author,
......@@ -66,25 +62,18 @@ BEGIN
FROM hive_posts_view hp
JOIN
(
SELECT hfc.post_id
SELECT hfc.post_id, hfc.created_at
FROM hive_feed_cache hfc
LEFT JOIN
(
SELECT
hp.id
FROM
hive_posts_view hp
LEFT JOIN hive_reblogs hr ON hp.id = hr.post_id
WHERE
hp.author_id = __account_id
AND hp.depth = 0
AND hp.community_id IS NOT NULL
) T ON hfc.post_id = T.id
WHERE hfc.account_id = __account_id AND ( __post_id = 0 OR hfc.created_at <= __created_at )
ORDER BY hfc.created_at DESC
WHERE hfc.account_id = __account_id AND (__post_id = 0 OR hfc.created_at <= __created_at)
AND NOT EXISTS (SELECT NULL FROM hive_posts hp
WHERE hp.id = hfc.post_id AND hp.counter_deleted = 0 AND hp.depth = 0 AND hp.community_id IS NOT NULL
AND NOT EXISTS (SELECT NULL FROM hive_reblogs hr WHERE hr.blogger_id = __account_id AND hr.post_id = hp.id)
)
ORDER BY created_at DESC
LIMIT _limit
)T ON hp.id = T.post_id
LIMIT _limit;
ORDER BY T.created_at DESC
;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_by_feed_with_reblog;
DROP FUNCTION IF EXISTS bridge_get_by_feed_with_reblog;
CREATE OR REPLACE FUNCTION condenser_get_by_feed_with_reblog(
in _account VARCHAR,
in _author VARCHAR,
in _permlink VARCHAR,
in _limit INTEGER
)
RETURNS SETOF bridge_api_post
AS
$function$
CREATE OR REPLACE FUNCTION bridge_get_by_feed_with_reblog( IN _account VARCHAR, IN _author VARCHAR, IN _permlink VARCHAR, IN _limit INTEGER)
RETURNS SETOF bridge_api_post_reblogs
LANGUAGE 'plpgsql'
STABLE
ROWS 1000
AS $BODY$
DECLARE
__post_id INTEGER := 0;
__cutoff INTEGER;
__cutoff INTEGER := 0;
__account_id INTEGER := find_account_id( _account, True );
__min_data TIMESTAMP;
__min_date TIMESTAMP;
BEGIN
IF _permlink <> '' THEN
__post_id = find_comment_id( _author, _permlink, True );
SELECT MIN(hfc.created_at) INTO __min_date
FROM hive_feed_cache hfc
JOIN hive_follows hf ON hfc.account_id = hf.following
WHERE hf.state = 1 AND hf.follower = __account_id AND hfc.post_id = __post_id;
END IF;
__cutoff = block_before_head( '1 month' );
__min_data =
(
SELECT MIN(hfc.created_at)
FROM hive_feed_cache hfc
JOIN hive_follows hf ON hfc.account_id = hf.following
WHERE hf.state = 1 AND hf.follower = __account_id AND ( ( __post_id = 0 ) OR ( hfc.post_id = __post_id ) )
);
RETURN QUERY SELECT
RETURN QUERY SELECT -- bridge_get_by_feed_with_reblog
hp.id,
hp.author,
hp.parent_author,
......@@ -65,25 +59,22 @@ BEGIN
hp.community_title,
hp.role_id,
hp.is_pinned,
hp.curator_payout_value
hp.curator_payout_value,
T.reblogged_by
FROM hive_posts_view hp
JOIN
(
SELECT hfc.post_id
SELECT hfc.post_id, MIN(hfc.created_at) as min_created, array_agg(ha.name) AS reblogged_by
FROM hive_feed_cache hfc
JOIN
(
SELECT following
FROM hive_follows
WHERE state = 1 AND follower = __account_id
) T ON hfc.account_id = T.following
JOIN hive_feed_cache hfc2 ON hfc2.account_id = T.following AND( __post_id = 0 OR hfc.post_id <= __post_id )
WHERE hfc.block_num > __cutoff
JOIN hive_follows hf ON hfc.account_id = hf.following
JOIN hive_accounts ha ON ha.id = hf.following
WHERE hfc.block_num > __cutoff AND hf.state = 1 AND hf.follower = __account_id
GROUP BY hfc.post_id
HAVING ( __post_id = 0 ) OR ( MIN(hfc.created_at) <= __min_data )
ORDER BY MIN(hfc.created_at) DESC
HAVING __post_id = 0 OR MIN(hfc.created_at) <= __min_date
ORDER BY min_created DESC
LIMIT _limit
) T ON hp.id = T.post_id;
) T ON hp.id = T.post_id
ORDER BY T.min_created DESC;
END
$function$
language plpgsql STABLE;
$BODY$
;
......@@ -270,7 +270,7 @@ $function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_payout;
CREATE FUNCTION bridge_get_ranked_post_by_payout( in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
CREATE FUNCTION bridge_get_ranked_post_by_payout( in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT, in _bridge_api BOOLEAN )
RETURNS SETOF bridge_api_post
AS
$function$
......@@ -328,7 +328,8 @@ BEGIN
, ( hp1.payout + hp1.pending_payout ) as all_payout
FROM
hive_posts hp1
WHERE 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'
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 ) )
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
......
......@@ -50,7 +50,7 @@ $function$
language sql STABLE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_trends_for_community;
CREATE FUNCTION bridge_get_ranked_post_by_trends_for_community( in _community VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
CREATE FUNCTION bridge_get_ranked_post_by_trends_for_community( in _community VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT, in _bridge_api BOOLEAN )
RETURNS SETOF bridge_api_post
AS
$function$
......@@ -107,7 +107,8 @@ BEGIN
FROM
hive_posts hp1
JOIN hive_communities hc ON hp1.community_id = hc.id
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND NOT hp1.is_paidout AND hp1.depth = 0 AND NOT hp1.is_pinned -- concatenated with bridge_get_ranked_post_pinned_for_community
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 ) )
ORDER BY hp1.sc_trend DESC, hp1.id DESC
LIMIT _limit
......@@ -473,7 +474,7 @@ $function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_created_for_community;
CREATE FUNCTION bridge_get_ranked_post_by_created_for_community( in _community VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
CREATE FUNCTION bridge_get_ranked_post_by_created_for_community( in _community VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT, in _bridge_api BOOLEAN )
RETURNS SETOF bridge_api_post
AS
$function$
......@@ -526,7 +527,8 @@ BEGIN
hive_posts hp1
JOIN hive_communities hc ON hp1.community_id = hc.id
JOIN hive_accounts_view ha ON hp1.author_id = ha.id
WHERE hc.name = _community AND hp1.counter_deleted = 0 AND hp1.depth = 0 AND NOT hp1.is_pinned -- concatenated with bridge_get_ranked_post_pinned_for_community
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 NOT ha.is_grayed AND ( __post_id = 0 OR hp1.id < __post_id )
ORDER BY hp1.id DESC
LIMIT _limit
......
......@@ -283,7 +283,7 @@ $function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS bridge_get_ranked_post_by_payout_for_category;
CREATE FUNCTION bridge_get_ranked_post_by_payout_for_category( in _category VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
CREATE FUNCTION bridge_get_ranked_post_by_payout_for_category( in _category VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT, in _bridge_api BOOLEAN )
RETURNS SETOF bridge_api_post
AS
$function$
......@@ -343,7 +343,8 @@ BEGIN
, ( hp1.payout + hp1.pending_payout ) as all_payout
FROM
hive_posts hp1
WHERE hp1.category_id = __hive_category 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'
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 ) )
ORDER BY ( hp1.payout + hp1.pending_payout ) DESC, hp1.id DESC
LIMIT _limit
......
......@@ -37,3 +37,44 @@ CREATE TYPE bridge_api_post AS (
is_pinned BOOLEAN,
curator_payout_value VARCHAR
);
DROP TYPE IF EXISTS bridge_api_post_reblogs CASCADE;
CREATE TYPE bridge_api_post_reblogs AS (
id INTEGER,
author VARCHAR,
parent_author VARCHAR,
author_rep BIGINT,
root_title VARCHAR,
beneficiaries JSON,
max_accepted_payout VARCHAR,
percent_hbd INTEGER,
url TEXT,
permlink VARCHAR,
parent_permlink_or_category VARCHAR,
title VARCHAR,
body TEXT,
category VARCHAR,
depth SMALLINT,
promoted DECIMAL(10,3),
payout DECIMAL(10,3),
pending_payout DECIMAL(10,3),
payout_at TIMESTAMP,
is_paidout BOOLEAN,
children INTEGER,
votes INTEGER,
created_at TIMESTAMP,
updated_at TIMESTAMP,
rshares NUMERIC,
abs_rshares NUMERIC,
json TEXT,
is_hidden BOOLEAN,
is_grayed BOOLEAN,
total_votes BIGINT,
sc_trend FLOAT4,
role_title VARCHAR,
community_title VARCHAR,
role_id SMALLINT,
is_pinned BOOLEAN,
curator_payout_value VARCHAR,
reblogged_by VARCHAR[]
);
DROP FUNCTION IF EXISTS condenser_get_follow_count;
CREATE FUNCTION condenser_get_follow_count( in _account VARCHAR,
out following hive_accounts.following%TYPE, out followers hive_accounts.followers%TYPE )
AS
$function$
DECLARE
__account_id INT;
BEGIN
__account_id = find_account_id( _account, True );
SELECT ha.following, ha.followers INTO following, followers FROM hive_accounts ha WHERE ha.id = __account_id;
-- following equals (SELECT COUNT(*) FROM hive_follows WHERE state = 1 AND following = __account_id)
-- followers equals (SELECT COUNT(*) FROM hive_follows WHERE state = 1 AND follower = __account_id)
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_followers;
-- list of account names that follow/ignore given account
CREATE FUNCTION condenser_get_followers( in _account VARCHAR, in _start VARCHAR, in _type INT, in _limit INT )
RETURNS SETOF hive_accounts.name%TYPE
AS
$function$
DECLARE
__account_id INT;
__start_id INT;
BEGIN
__account_id = find_account_id( _account, True );
__start_id = find_account_id( _start, _start <> '' );
IF __start_id <> 0 THEN
SELECT INTO __start_id COALESCE( ( SELECT id FROM hive_follows WHERE following = __account_id AND follower = __start_id ), 0 );
END IF;
RETURN QUERY SELECT
ha.name
FROM
hive_follows hf
JOIN hive_accounts ha ON hf.follower = ha.id
WHERE
hf.following = __account_id AND hf.state = _type AND ( __start_id = 0 OR hf.id < __start_id )
ORDER BY hf.id DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_following;
-- list of account names followed/ignored by given account
CREATE FUNCTION condenser_get_following( in _account VARCHAR, in _start VARCHAR, in _type INT, in _limit INT )
RETURNS SETOF hive_accounts.name%TYPE
AS
$function$
DECLARE
__account_id INT;
__start_id INT;
BEGIN
__account_id = find_account_id( _account, True );
__start_id = find_account_id( _start, _start <> '' );
IF __start_id <> 0 THEN
SELECT INTO __start_id COALESCE( ( SELECT id FROM hive_follows WHERE follower = __account_id AND following = __start_id ), 0 );
END IF;
RETURN QUERY SELECT
ha.name
FROM
hive_follows hf
JOIN hive_accounts ha ON hf.following = ha.id
WHERE
hf.follower = __account_id AND hf.state = _type AND ( __start_id = 0 OR hf.id < __start_id )
ORDER BY hf.id DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_comment_discussions_by_payout;
CREATE FUNCTION condenser_get_comment_discussions_by_payout( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
WHERE hp.is_paidout = '0' AND hp.depth > 0 AND ( __category_id = 0 OR hp.category_id = __category_id )
ORDER BY (hp.payout+hp.pending_payout) DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_created;
CREATE FUNCTION condenser_get_discussions_by_created( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__tag_id INT;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__tag_id = ( SELECT id FROM hive_tag_data WHERE tag = _tag );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
INNER JOIN hive_post_tags hpt ON hpt.post_id = hp.id
WHERE ( __tag_id = 0 OR hpt.tag_id = __tag_id ) AND ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( __category_id = 0 OR hp.category_id = __category_id ) ) )
ORDER BY hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_created_with_empty_tag;
CREATE FUNCTION condenser_get_discussions_by_created_with_empty_tag( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
WHERE ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( __category_id = 0 OR hp.category_id = __category_id ) ) )
ORDER BY hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_hot;
CREATE FUNCTION condenser_get_discussions_by_hot( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__tag_id INT;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__tag_id = ( SELECT id FROM hive_tag_data WHERE tag = _tag );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
INNER JOIN hive_post_tags hpt ON hpt.post_id = hp.id
WHERE hp.is_paidout = '0' AND ( __tag_id = 0 OR hpt.tag_id = __tag_id ) AND ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( ( __category_id = 0 OR hp.category_id = __category_id ) AND hp.depth = 0 ) ) )
ORDER BY hp.sc_hot DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_hot_with_empty_tag;
CREATE FUNCTION condenser_get_discussions_by_hot_with_empty_tag( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
WHERE hp.is_paidout = '0' AND ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( ( __category_id = 0 OR hp.category_id = __category_id ) AND hp.depth = 0 ) ) )
ORDER BY hp.sc_hot DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_promoted;
CREATE FUNCTION condenser_get_discussions_by_promoted( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__tag_id INT;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__tag_id = ( SELECT id FROM hive_tag_data WHERE tag = _tag );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
INNER JOIN hive_post_tags hpt ON hpt.post_id = hp.id
WHERE hp.promoted > 0 AND ( __tag_id = 0 OR hpt.tag_id = __tag_id ) AND ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( __category_id = 0 OR hp.category_id = __category_id ) ) )
ORDER BY hp.promoted DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_promoted_with_empty_tag;
CREATE FUNCTION condenser_get_discussions_by_promoted_with_empty_tag( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
INNER JOIN hive_post_tags hpt ON hpt.post_id = hp.id
WHERE hp.promoted > 0 AND ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( __category_id = 0 OR hp.category_id = __category_id ) ) )
ORDER BY hp.promoted DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_trending;
CREATE FUNCTION condenser_get_discussions_by_trending( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__tag_id INT;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__tag_id = ( SELECT id FROM hive_tag_data WHERE tag = _tag );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
INNER JOIN hive_post_tags hpt ON hpt.post_id = hp.id
WHERE hp.is_paidout = '0' AND ( __tag_id = 0 OR hpt.tag_id = __tag_id ) AND ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( ( __category_id = 0 OR hp.category_id = __category_id ) AND hp.depth = 0 ) ) )
ORDER BY hp.sc_trend DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_discussions_by_trending_with_empty_tag;
CREATE FUNCTION condenser_get_discussions_by_trending_with_empty_tag( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__community VARCHAR;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__community = ( SELECT substring(_tag from '^hive-') );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
WHERE hp.is_paidout = '0' AND ( __post_id = 0 OR hp.id < __post_id )
AND ( ( __community IS NULL ) OR ( ( __community IS NOT NULL ) AND ( ( __category_id = 0 OR hp.category_id = __category_id ) AND hp.depth = 0 ) ) )
ORDER BY hp.sc_trend DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_follow_counts;
CREATE FUNCTION condenser_get_follow_counts( in _account VARCHAR )
RETURNS TABLE(
following hive_accounts.following%TYPE,
followers hive_accounts.followers%TYPE
)
AS
$function$
DECLARE
BEGIN
RETURN QUERY SELECT
ha.following, ha.followers
FROM hive_accounts ha
WHERE ha.name = _account;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_names_by_followers;
CREATE FUNCTION condenser_get_names_by_followers( in _account VARCHAR, in _start_account VARCHAR, in _state SMALLINT, _limit SMALLINT )
RETURNS TABLE(
names hive_accounts.name%TYPE
)
AS
$function$
DECLARE
__account_id INT := find_account_id( _account, True );
__start_account_id INT := 0;
__created_at TIMESTAMP;
BEGIN
IF _start_account <> '' THEN
__start_account_id = find_account_id( _start_account, True );
END IF;
IF __start_account_id <> 0 THEN
SELECT hf.created_at
INTO __created_at
FROM hive_follows hf
WHERE hf.following = __account_id AND hf.follower = __start_account_id;
END IF;
RETURN QUERY SELECT
name
FROM hive_follows hf
LEFT JOIN hive_accounts ha ON hf.follower = ha.id
WHERE hf.following = __account_id
AND state = _state
AND ( __start_account_id = 0 OR hf.created_at <= __created_at )
ORDER BY hf.created_at DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_names_by_following;
CREATE FUNCTION condenser_get_names_by_following( in _account VARCHAR, in _start_account VARCHAR, in _state SMALLINT, _limit SMALLINT )
RETURNS TABLE(
names hive_accounts.name%TYPE
)
AS
$function$
DECLARE
__account_id INT := find_account_id( _account, True );
__start_account_id INT := 0;
__created_at TIMESTAMP;
BEGIN
IF _start_account <> '' THEN
__start_account_id = find_account_id( _start_account, True );
END IF;
IF __start_account_id <> 0 THEN
SELECT hf.created_at
INTO __created_at
FROM hive_follows hf
WHERE hf.follower = __account_id AND hf.following = __start_account_id;
END IF;
RETURN QUERY SELECT
name
FROM hive_follows hf
LEFT JOIN hive_accounts ha ON hf.following = ha.id
WHERE hf.follower = __account_id
AND state = _state
AND ( __start_account_id = 0 OR hf.created_at <= __created_at )
ORDER BY hf.created_at DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_post_discussions_by_payout;
CREATE FUNCTION condenser_get_post_discussions_by_payout( in _tag VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INT;
__category_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__category_id = ( SELECT id FROM hive_category_data WHERE category = _tag );
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
FROM hive_posts_view hp
WHERE hp.is_paidout = '0' AND hp.depth = 0 AND ( __category_id = 0 OR hp.category_id = __category_id )
ORDER BY (hp.payout+hp.pending_payout) DESC, hp.id DESC LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_top_trending_tags_summary;
CREATE FUNCTION condenser_get_top_trending_tags_summary( in _limit INT )
RETURNS SETOF VARCHAR
AS
$function$
BEGIN
RETURN QUERY SELECT
hcd.category
FROM
hive_category_data hcd
JOIN hive_posts hp ON hp.category_id = hcd.id
WHERE hp.counter_deleted = 0 AND NOT hp.is_paidout
GROUP BY hcd.category
ORDER BY SUM(hp.payout + hp.pending_payout) DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_trending_tags;
CREATE FUNCTION condenser_get_trending_tags( in _category VARCHAR, in _limit INT )
RETURNS TABLE( category VARCHAR, total_posts BIGINT, top_posts BIGINT, total_payouts hive_posts.payout%TYPE )
AS
$function$
DECLARE
__category_id INT;
__payout_limit hive_posts.payout%TYPE;
BEGIN
__category_id = find_category_id( _category, _category <> '' );
IF __category_id <> 0 THEN
SELECT SUM(hp.payout + hp.pending_payout) INTO __payout_limit
FROM hive_posts hp
WHERE hp.category_id = __category_id AND hp.counter_deleted = 0 AND NOT hp.is_paidout;
END IF;
RETURN QUERY SELECT
hcd.category,
COUNT(*) AS total_posts,
SUM(CASE WHEN hp.depth = 0 THEN 1 ELSE 0 END) AS top_posts,
SUM(hp.payout + hp.pending_payout) AS total_payouts
FROM
hive_posts hp
JOIN hive_category_data hcd ON hcd.id = hp.category_id
WHERE NOT hp.is_paidout AND counter_deleted = 0
GROUP BY hcd.category
HAVING __category_id = 0 OR SUM(hp.payout + hp.pending_payout) < __payout_limit OR ( SUM(hp.payout + hp.pending_payout) = __payout_limit AND hcd.category > _category )
ORDER BY SUM(hp.payout + hp.pending_payout) DESC, hcd.category ASC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
......@@ -41,14 +41,10 @@ for sql in postgres_handle_view_changes.sql \
condenser_api_post_ex_type.sql \
condenser_get_blog.sql \
condenser_get_content.sql \
condenser_get_discussions_by_created.sql \
condenser_get_discussions_by_blog.sql \
condenser_tags.sql \
condenser_follows.sql \
hot_and_trends.sql \
condenser_get_discussions_by_trending.sql \
condenser_get_discussions_by_hot.sql \
condenser_get_discussions_by_promoted.sql \
condenser_get_post_discussions_by_payout.sql \
condenser_get_comment_discussions_by_payout.sql \
update_hive_posts_children_count.sql \
update_hive_posts_api_helper.sql \
database_api_list_comments.sql \
......@@ -58,17 +54,16 @@ for sql in postgres_handle_view_changes.sql \
condenser_get_by_replies_to_account.sql \
condenser_get_by_account_comments.sql \
condenser_get_by_blog_without_reblog.sql \
condenser_get_by_feed_with_reblog.sql \
bridge_get_by_feed_with_reblog.sql \
condenser_get_by_blog.sql \
bridge_get_account_posts_by_blog.sql \
condenser_get_follow_counts.sql \
condenser_get_names_by_followers.sql \
condenser_get_names_by_following.sql \
condenser_get_names_by_reblogged.sql
condenser_get_names_by_reblogged.sql \
condenser_get_discussions_by_comments.sql \
condenser_get_account_reputations.sql
do
echo Executing psql -U $1 -d $2 -f $sql
time psql -1 -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f $sql 2>&1 | tee -a -i upgrade.log
echo Executing psql -U $1 -d $2 -f $sql
time psql -1 -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f $sql 2>&1 | tee -a -i upgrade.log
echo $?
done
......