Skip to content
Snippets Groups Projects
Commit fddd29e8 authored by Mariusz Trela's avatar Mariusz Trela
Browse files

The call `get_state` works + a few fixes in `get_discussion*` queries

parent c38cedc4
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!297get state fix
......@@ -62,3 +62,65 @@ BEGIN
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;
......@@ -62,3 +62,65 @@ BEGIN
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;
......@@ -62,3 +62,66 @@ BEGIN
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;
......@@ -62,3 +62,65 @@ BEGIN
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;
......@@ -247,13 +247,25 @@ async def get_posts_by_given_sort(context, sort: str, start_author: str = '', st
posts = []
if sort == 'created':
sql = "SELECT * FROM condenser_get_discussions_by_created( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
if tag == '':
sql = "SELECT * FROM condenser_get_discussions_by_created_with_empty_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
else:
sql = "SELECT * FROM condenser_get_discussions_by_created( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
elif sort == 'trending':
sql = "SELECT * FROM condenser_get_discussions_by_trending( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
if tag == '':
sql = "SELECT * FROM condenser_get_discussions_by_trending_with_empty_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
else:
sql = "SELECT * FROM condenser_get_discussions_by_trending( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
elif sort == 'hot':
sql = "SELECT * FROM condenser_get_discussions_by_hot( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
if tag == '':
sql = "SELECT * FROM condenser_get_discussions_by_hot_with_empty_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
else:
sql = "SELECT * FROM condenser_get_discussions_by_hot( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
elif sort == 'promoted':
sql = "SELECT * FROM condenser_get_discussions_by_promoted( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
if tag == '':
sql = "SELECT * FROM condenser_get_discussions_by_promoted_with_empty_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
else:
sql = "SELECT * FROM condenser_get_discussions_by_promoted( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
elif sort == 'post_by_payout':
sql = "SELECT * FROM condenser_get_post_discussions_by_payout( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
elif sort == 'comment_by_payout':
......
Subproject commit ae53a82f46e6338a04e40b4966f8e7b0e64e6c86
Subproject commit e1439046adf7900ba3d6cbaeb5615d4dc6c837b5
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