Skip to content
Snippets Groups Projects
Commit 0391230a authored by Andrzej Lisak's avatar Andrzej Lisak
Browse files

[ABW]: find_tag_id/find_category_id moved to utility_functions.sql and changed...

[ABW]: find_tag_id/find_category_id moved to utility_functions.sql and changed so they follow example of find_comment_id with their error handling
added extra promotion and new ignored accounts in mock data for observer tests
observer in get_ranked_posts is now validated (it was actually validated already, but only after main query, now it happens as early as possible)
fixed problem with default value of limit in get_ranked_posts (when explicit null was passed); also all string params now are empty instead of None
parent 63612fe2
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!416Small fixes and mock data for observer tests in get_ranked_posts
Showing
with 87 additions and 72 deletions
......@@ -563,7 +563,6 @@ def setup(db):
"update_feed_cache.sql",
"payout_stats_view.sql",
"update_hive_posts_mentions.sql",
"find_tag_id.sql",
"mutes.sql",
"bridge_get_ranked_post_type.sql",
"bridge_get_ranked_post_for_communities.sql",
......
......@@ -8,7 +8,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -76,7 +76,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -220,7 +220,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -294,7 +294,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -369,7 +369,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -442,7 +442,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......
......@@ -6,7 +6,7 @@ $function$
DECLARE
__observer_id INT;
BEGIN
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -67,7 +67,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -142,7 +142,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -217,7 +217,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id( _observer, False );
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -292,7 +292,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -438,7 +438,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
IF __post_id <> 0 THEN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
......@@ -511,7 +511,7 @@ DECLARE
__observer_id INT;
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......
......@@ -10,7 +10,7 @@ DECLARE
BEGIN
__post_id = find_comment_id( _author, _permlink, True );
__hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True ));
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -85,7 +85,7 @@ BEGIN
SELECT hp.sc_hot INTO __hot_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True ));
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -233,7 +233,7 @@ BEGIN
SELECT ( hp.payout + hp.pending_payout ) INTO __payout_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_category = find_category_id( _category, True );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -310,7 +310,7 @@ BEGIN
END IF;
__hive_category = find_category_id( _category, True );
__head_block_time = head_block_time();
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -386,7 +386,7 @@ BEGIN
SELECT hp.promoted INTO __promoted_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True ) );
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......@@ -461,7 +461,7 @@ BEGIN
SELECT hp.sc_trend INTO __trending_limit FROM hive_posts hp WHERE hp.id = __post_id;
END IF;
__hive_tag = ARRAY_APPEND( __hive_tag, find_tag_id( _tag, True ));
__observer_id = find_account_id(_observer, False);
__observer_id = find_account_id( _observer, True );
RETURN QUERY SELECT
hp.id,
hp.author,
......
......@@ -26,7 +26,7 @@ DECLARE
__category_id INT;
__payout_limit hive_posts.payout%TYPE;
BEGIN
__category_id = find_category_id( _category, _category <> '' );
__category_id = find_category_id( _category, True );
IF __category_id <> 0 THEN
SELECT SUM(hp.payout + hp.pending_payout) INTO __payout_limit
FROM hive_posts hp
......
......@@ -21,7 +21,6 @@ for sql in postgres_handle_view_changes.sql \
update_feed_cache.sql \
payout_stats_view.sql \
update_hive_posts_mentions.sql \
find_tag_id.sql \
mutes.sql \
bridge_get_ranked_post_type.sql \
bridge_get_ranked_post_for_communities.sql \
......
DROP FUNCTION IF EXISTS public.find_tag_id CASCADE;
CREATE OR REPLACE FUNCTION public.find_tag_id(
in _tag_name hive_tag_data.tag%TYPE,
in _check BOOLEAN
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
AS
$BODY$
DECLARE
__tag_id INTEGER;
BEGIN
SELECT INTO __tag_id COALESCE( ( SELECT id FROM hive_tag_data WHERE tag=_tag_name ), 0 );
IF _check AND __tag_id = 0 THEN
RAISE EXCEPTION 'Tag % does not exist', _tag_name;
END IF;
RETURN __tag_id;
END
$BODY$
;
DROP FUNCTION IF EXISTS public.find_category_id CASCADE;
CREATE OR REPLACE FUNCTION public.find_category_id(
in _category_name hive_category_data.category%TYPE,
in _check BOOLEAN
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
AS
$BODY$
DECLARE
__category_id INTEGER;
BEGIN
SELECT INTO __category_id COALESCE( ( SELECT id FROM hive_category_data WHERE category=_category_name ), 0 );
IF _check AND __category_id = 0 THEN
RAISE EXCEPTION 'Category % does not exist', _category_name;
END IF;
RETURN __category_id;
END
$BODY$
;
......@@ -76,3 +76,51 @@ BEGIN
END
$function$
;
DROP FUNCTION IF EXISTS public.find_tag_id CASCADE
;
CREATE OR REPLACE FUNCTION public.find_tag_id(
in _tag_name hive_tag_data.tag%TYPE,
in _check BOOLEAN
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
AS
$function$
DECLARE
__tag_id INT = 0;
BEGIN
IF (_tag_name <> '') THEN
SELECT INTO __tag_id COALESCE( ( SELECT id FROM hive_tag_data WHERE tag=_tag_name ), 0 );
IF _check AND __tag_id = 0 THEN
RAISE EXCEPTION 'Tag % does not exist', _tag_name;
END IF;
END IF;
RETURN __tag_id;
END
$function$
;
DROP FUNCTION IF EXISTS public.find_category_id CASCADE
;
CREATE OR REPLACE FUNCTION public.find_category_id(
in _category_name hive_category_data.category%TYPE,
in _check BOOLEAN
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
AS
$function$
DECLARE
__category_id INT = 0;
BEGIN
IF (_category_name <> '') THEN
SELECT INTO __category_id COALESCE( ( SELECT id FROM hive_category_data WHERE category=_category_name ), 0 );
IF _check AND __category_id = 0 THEN
RAISE EXCEPTION 'Category % does not exist', _category_name;
END IF;
END IF;
RETURN __category_id;
END
$function$
;
......@@ -222,7 +222,7 @@ async def _get_ranked_posts_for_all( db, sort:str, start_author:str, start_perml
@return_error_info
async def get_ranked_posts(context, sort:str, start_author:str='', start_permlink:str='',
limit:int=20, tag:str=None, observer:str=None):
limit:int=20, tag:str='', observer:str=''):
"""Query posts, sorted by given method."""
supported_sort_list = ['trending', 'hot', 'created', 'promoted', 'payout', 'payout_comments', 'muted']
assert sort in supported_sort_list, "Unsupported sort, valid sorts: {}".format(", ".join(supported_sort_list))
......@@ -241,11 +241,11 @@ async def get_ranked_posts(context, sort:str, start_author:str='', start_permlin
posts.append(post)
return posts
valid_account(start_author, allow_empty=True)
valid_permlink(start_permlink, allow_empty=True)
valid_limit(limit, 100, 20)
valid_tag(tag, allow_empty=True)
valid_account(observer, allow_empty=(tag != "my"))
start_author = valid_account(start_author, allow_empty=True)
start_permlink = valid_permlink(start_permlink, allow_empty=True)
limit = valid_limit(limit, 100, 20)
tag = valid_tag(tag, allow_empty=True)
observer = valid_account(observer, allow_empty=(tag != "my"))
if tag == "my":
result = await _get_ranked_posts_for_observer_communities(db, sort, start_author, start_permlink, limit, observer)
......
......@@ -16,7 +16,7 @@ async def get_trending_tags(context, start_tag: str = '', limit: int = 250):
"""Get top 250 trending tags among pending posts, with stats."""
limit = valid_limit(limit, 250, 250)
start_tag = valid_tag(start_tag or '', allow_empty=True)
start_tag = valid_tag(start_tag, allow_empty=True)
sql = "SELECT * FROM condenser_get_trending_tags( (:tag)::VARCHAR, :limit )"
......
......@@ -11,6 +11,7 @@ account_create_operation( `hive-149232` )
account_create_operation( `hive-104647` )
comment_operation( `hive-135485`, `test-safari`, `secrets1`)
comment_operation( `hive-135485`, `test-safari`, `secrets2`)
transfer_opearation( `test-safari`, `null`, `0.010666 HBD`, `@test-safari/secrets2` ) - post promotion (with bad amount precision to see what happens - rounding occurs)
comment_operation( `hive-117600`, `test-safari`, `secrets3`)
comment_operation( `hive-117600`, `test-safari`, `secrets4`)
comment_operation( `hive-117600`, `test-safari`, `secrets5`)
......
......@@ -436,6 +436,15 @@
"json_metadata": "{}"
}
},
{
"type": "transfer_operation",
"value": {
"from": "test-safari",
"to": "null",
"amount": "0.010666 HBD",
"memo": "@test-safari/secrets2"
}
},
{
"type": "comment_operation",
"value": {
......
......@@ -748,7 +748,7 @@
"ignoreall"
],
"id": "follow",
"json": "[\"follow\",{\"follower\":\"ignoreall\",\"following\":[\"gtg\",\"alice\",\"davr86\"],\"what\":[\"ignore\"]}]"
"json": "[\"follow\",{\"follower\":\"ignoreall\",\"following\":[\"gtg\",\"alice\",\"davr86\",\"fyrstikken\",\"gavvet\",\"ooak\",\"kental\",\"r4fken\",\"roland.haynes\",\"agartha\",\"feline1991\"],\"what\":[\"ignore\"]}]"
}
}
]
......
Subproject commit 87c4457827200ef54f8fe64f942df641a9f1b1af
Subproject commit 204e7fa2128efdfd5c197bc2ab76fc37e414cc88
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