diff --git a/hive/db/sql_scripts/bridge_get_discussion.sql b/hive/db/sql_scripts/bridge_get_discussion.sql index 61d334333f69953aa7ddd9aca5c31fdb08d4ae0e..e4450cfd0d8a88d681503a5b53e76ccd02ed3316 100644 --- a/hive/db/sql_scripts/bridge_get_discussion.sql +++ b/hive/db/sql_scripts/bridge_get_discussion.sql @@ -1,6 +1,6 @@ -DROP FUNCTION IF EXISTS get_discussion +DROP FUNCTION IF EXISTS bridge_get_discussion ; -CREATE OR REPLACE FUNCTION get_discussion( +CREATE OR REPLACE FUNCTION bridge_get_discussion( in _author hive_accounts.name%TYPE, in _permlink hive_permlink_data.permlink%TYPE, in _observer VARCHAR @@ -14,9 +14,9 @@ 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 + SELECT -- bridge_get_discussion hpv.id, hpv.author, hpv.parent_author, diff --git a/hive/db/sql_scripts/condenser_follows.sql b/hive/db/sql_scripts/condenser_follows.sql index 035824619169402349509d65a89a4e446ff7263f..9c90c4fec640449f2e6fed619e22f5270379c7e7 100644 --- a/hive/db/sql_scripts/condenser_follows.sql +++ b/hive/db/sql_scripts/condenser_follows.sql @@ -25,7 +25,7 @@ DECLARE __start_id INT; BEGIN __account_id = find_account_id( _account, True ); - __start_id = find_account_id( _start, _start <> '' ); + __start_id = find_account_id( _start, True ); IF __start_id <> 0 THEN SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE following = __account_id AND follower = __start_id ); END IF; @@ -53,7 +53,7 @@ DECLARE __start_id INT; BEGIN __account_id = find_account_id( _account, True ); - __start_id = find_account_id( _start, _start <> '' ); + __start_id = find_account_id( _start, True ); IF __start_id <> 0 THEN SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE follower = __account_id AND following = __start_id ); END IF; diff --git a/hive/db/sql_scripts/database_api_list_votes.sql b/hive/db/sql_scripts/database_api_list_votes.sql index 89cd9256d3b8ee48509bf3322706dbfe72bfb5c2..df591ebf1ef229179c2488845f3a8ec2ffd7badf 100644 --- a/hive/db/sql_scripts/database_api_list_votes.sql +++ b/hive/db/sql_scripts/database_api_list_votes.sql @@ -117,7 +117,7 @@ DECLARE __voter_id INT; DECLARE __post_id INT; BEGIN -__voter_id = find_account_id( _VOTER, _VOTER != '' ); -- voter is optional +__voter_id = find_account_id( _VOTER, True ); __post_id = find_comment_id( _AUTHOR, _PERMLINK, True ); RETURN QUERY diff --git a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql index b4bb9f5b82359b7cf280fed5c04e2dcf34fa6083..1bfc959c06d08780d8a1f6f9539a4e4ad740db4e 100644 --- a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql +++ b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql @@ -228,7 +228,7 @@ IF NOT EXISTS(SELECT data_type FROM information_schema.columns UPDATE hive_posts hp SET - tags_ids = tags.tags + tags_ids = tags.tags FROM ( SELECT @@ -237,7 +237,7 @@ IF NOT EXISTS(SELECT data_type FROM information_schema.columns FROM hive_post_tags hpt GROUP BY post_id - ) as tags + ) as tags WHERE hp.id = tags.post_id; ELSE RAISE NOTICE 'SKIPPING hive_posts upgrade - adding a tags_ids column'; diff --git a/hive/db/sql_scripts/utility_functions.sql b/hive/db/sql_scripts/utility_functions.sql index 7c632ac7f5b1c6c18957e05775eceb2113fa187b..098af5bf66593294dce76615a534e81fc9f8d538 100644 --- a/hive/db/sql_scripts/utility_functions.sql +++ b/hive/db/sql_scripts/utility_functions.sql @@ -64,13 +64,15 @@ LANGUAGE 'plpgsql' AS $function$ DECLARE - account_id INT; + __account_id INT = 0; BEGIN - SELECT INTO account_id COALESCE( ( SELECT id FROM hive_accounts WHERE name=_account ), 0 ); - IF _check AND account_id = 0 THEN - RAISE EXCEPTION 'Account % does not exist', _account; + IF (_account <> '') THEN + SELECT INTO __account_id COALESCE( ( SELECT id FROM hive_accounts WHERE name=_account ), 0 ); + IF _check AND __account_id = 0 THEN + RAISE EXCEPTION 'Account % does not exist', _account; + END IF; END IF; - RETURN account_id; + RETURN __account_id; END $function$ ; diff --git a/hive/server/bridge_api/thread.py b/hive/server/bridge_api/thread.py index d15e48a5b885fd76cca54c980d2c37e8284df1cf..bafe0c7681aa26b7dd02ee4b22aa620300c77e3a 100644 --- a/hive/server/bridge_api/thread.py +++ b/hive/server/bridge_api/thread.py @@ -13,20 +13,19 @@ from hive.server.common.mutes import Mutes log = logging.getLogger(__name__) @return_error_info -async def get_discussion(context, author, permlink, observer=None): +async def get_discussion(context, author:str, permlink:str, observer:str=''): """Modified `get_state` thread implementation.""" - # New index was created: hive_posts_parent_id_btree (CREATE INDEX "hive_posts_parent_id_btree" ON hive_posts btree(parent_id) - # We thougth this would be covered by "hive_posts_ix4" btree (parent_id, id) WHERE counter_deleted = 0 but it was not db = context['db'] author = valid_account(author) permlink = valid_permlink(permlink) + observer = valid_account(observer, allow_empty=True) blacklisted_for_user = None if observer: blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context) - sql = "SELECT * FROM get_discussion(:author,:permlink,:observer)" + sql = "SELECT * FROM bridge_get_discussion(:author,:permlink,:observer)" rows = await db.query_all(sql, author=author, permlink=permlink, observer=observer) if not rows or len(rows) == 0: return {} diff --git a/hive/server/condenser_api/get_state.py b/hive/server/condenser_api/get_state.py index 05221d462d1b300983f8abe9b588fde9b924f9a5..53081f12782d75cfb62ccab35b968179a89ed788 100644 --- a/hive/server/condenser_api/get_state.py +++ b/hive/server/condenser_api/get_state.py @@ -237,7 +237,7 @@ async def _child_ids(db, parent_ids): async def _load_discussion(db, author, permlink, observer=None): """Load a full discussion thread.""" - sql = "SELECT * FROM get_discussion(:author,:permlink,:observer)" + sql = "SELECT * FROM bridge_get_discussion(:author,:permlink,:observer)" sql_result = await db.query_all(sql, author=author, permlink=permlink, observer=observer) muted_accounts = Mutes.all() 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 c018e6c812e099353515505c283f9c20e8758a83..2d6c189d2dac39ea225df80b70d3cf88bd79f9bd 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 @@ -693,7 +693,7 @@ "spaminator" ], "id": "follow", - "json": "[\"follow\",{\"follower\":\"spaminator\",\"following\":[\"lyubovbar\",\"zaitsevalesyaa\",\"kingscrown\",\"trevonjb\",\"craig-grant\",\"ned\"],\"what\":[\"blacklist\"]}]" + "json": "[\"follow\",{\"follower\":\"spaminator\",\"following\":[\"lyubovbar\",\"zaitsevalesyaa\",\"kingscrown\",\"trevonjb\",\"craig-grant\",\"ned\",\"mindhunter\"],\"what\":[\"blacklist\"]}]" } }, { diff --git a/tests/tests_api b/tests/tests_api index 88c50bc23cece0e6ba9a80018d689a3eeea27e18..87c4457827200ef54f8fe64f942df641a9f1b1af 160000 --- a/tests/tests_api +++ b/tests/tests_api @@ -1 +1 @@ -Subproject commit 88c50bc23cece0e6ba9a80018d689a3eeea27e18 +Subproject commit 87c4457827200ef54f8fe64f942df641a9f1b1af