diff --git a/hive/db/schema.py b/hive/db/schema.py index f4d2d9c9e1b1ad8876509f1c6d8489964239a627..4e0a29d3449a6102e7b09b5f9afa3e57b9593ee1 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -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", diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql index 229985da24c0e0e903384ecc76114f5f449a5612..426d7b798bb1b7bdc2a3765016c3a07c3276d732 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_all.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; diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql index a6f1f91f72f4be3e7ef942a3ae43f75c25803aec..4658fcf76b1abbf0f8c84720a8646d32efb854af 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql @@ -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, diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql index dd098386725ae2e71820502bb86a929a58831c15..7c40c81a7c81ddaeadf6b0a6876bfd7f185770b2 100644 --- a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql +++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql @@ -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, diff --git a/hive/db/sql_scripts/condenser_tags.sql b/hive/db/sql_scripts/condenser_tags.sql index 0812832b4b04ef8eccef4f6aed217d057a893915..684da1c61df6f754a746b40de74e09e15265119d 100644 --- a/hive/db/sql_scripts/condenser_tags.sql +++ b/hive/db/sql_scripts/condenser_tags.sql @@ -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 diff --git a/hive/db/sql_scripts/db_upgrade.sh b/hive/db/sql_scripts/db_upgrade.sh index c45d409134e3e38c1b12c279b6de561f3d47637a..a6ec3b57f75ed5efa358204d58522c3daa5ba7af 100755 --- a/hive/db/sql_scripts/db_upgrade.sh +++ b/hive/db/sql_scripts/db_upgrade.sh @@ -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 \ diff --git a/hive/db/sql_scripts/find_tag_id.sql b/hive/db/sql_scripts/find_tag_id.sql deleted file mode 100644 index f35fef406b7118e7822a051efed43f9e568c61e6..0000000000000000000000000000000000000000 --- a/hive/db/sql_scripts/find_tag_id.sql +++ /dev/null @@ -1,41 +0,0 @@ -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$ -; diff --git a/hive/db/sql_scripts/utility_functions.sql b/hive/db/sql_scripts/utility_functions.sql index 098af5bf66593294dce76615a534e81fc9f8d538..896de4fe59565145d20cc5fe54be59ebc54f7754 100644 --- a/hive/db/sql_scripts/utility_functions.sql +++ b/hive/db/sql_scripts/utility_functions.sql @@ -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$ +; diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py index 1250cb1d90da174c27235c4b7299f2a8fe7f4e53..c9fb5ef0ef998cc8c879806a49473e8ba5ca66c4 100644 --- a/hive/server/bridge_api/methods.py +++ b/hive/server/bridge_api/methods.py @@ -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) diff --git a/hive/server/condenser_api/tags.py b/hive/server/condenser_api/tags.py index d6f05ca2b8d58a55ebf3a0367f6226deb016a039..d63cd62e04c77966c4fba052dd81ec800cd84d06 100644 --- a/hive/server/condenser_api/tags.py +++ b/hive/server/condenser_api/tags.py @@ -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 )" diff --git a/mock_data/block_data/community_op/flow.txt b/mock_data/block_data/community_op/flow.txt index ceb7dcbd73b096348be089ccddb71c6d186541d1..dd8778f8d9064a79f93089c243bca8a6958c47e4 100644 --- a/mock_data/block_data/community_op/flow.txt +++ b/mock_data/block_data/community_op/flow.txt @@ -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`) diff --git a/mock_data/block_data/community_op/mock_block_data_community.json b/mock_data/block_data/community_op/mock_block_data_community.json index 081b18678d04fe777e97cfd886faafc5b82781d3..4804a706a4de68d678944f21154239f8f399a52c 100644 --- a/mock_data/block_data/community_op/mock_block_data_community.json +++ b/mock_data/block_data/community_op/mock_block_data_community.json @@ -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": { diff --git a/mock_data/block_data/follow_op/mock_block_data_follow.json b/mock_data/block_data/follow_op/mock_block_data_follow.json index 2d6c189d2dac39ea225df80b70d3cf88bd79f9bd..f7ac08d2d6d644e47623bf4c0c65ef4c2fdda5fb 100644 --- a/mock_data/block_data/follow_op/mock_block_data_follow.json +++ b/mock_data/block_data/follow_op/mock_block_data_follow.json @@ -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\"]}]" } } ] diff --git a/tests/tests_api b/tests/tests_api index 87c4457827200ef54f8fe64f942df641a9f1b1af..204e7fa2128efdfd5c197bc2ab76fc37e414cc88 160000 --- a/tests/tests_api +++ b/tests/tests_api @@ -1 +1 @@ -Subproject commit 87c4457827200ef54f8fe64f942df641a9f1b1af +Subproject commit 204e7fa2128efdfd5c197bc2ab76fc37e414cc88