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

[ABW]: find_account_id changed to be similar to find_comment_id (other...

[ABW]: find_account_id changed to be similar to find_comment_id (other routines like that will likely follow) - True means the check will be performed, but not when account is empty (that needs to be blocked/allowed in python code)
get_discussion SQL function renamed to bridge_get_discussion
added validation of observer in get_discussion
parent e2ea2991
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!413Corrections related to bridge.get_discussion + some cleanup
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 _author hive_accounts.name%TYPE,
in _permlink hive_permlink_data.permlink%TYPE, in _permlink hive_permlink_data.permlink%TYPE,
in _observer VARCHAR in _observer VARCHAR
...@@ -14,9 +14,9 @@ DECLARE ...@@ -14,9 +14,9 @@ DECLARE
__observer_id INT; __observer_id INT;
BEGIN BEGIN
__post_id = find_comment_id( _author, _permlink, True ); __post_id = find_comment_id( _author, _permlink, True );
__observer_id = find_account_id(_observer, False); __observer_id = find_account_id( _observer, True );
RETURN QUERY RETURN QUERY
SELECT SELECT -- bridge_get_discussion
hpv.id, hpv.id,
hpv.author, hpv.author,
hpv.parent_author, hpv.parent_author,
......
...@@ -25,7 +25,7 @@ DECLARE ...@@ -25,7 +25,7 @@ DECLARE
__start_id INT; __start_id INT;
BEGIN BEGIN
__account_id = find_account_id( _account, True ); __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 IF __start_id <> 0 THEN
SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE following = __account_id AND follower = __start_id ); SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE following = __account_id AND follower = __start_id );
END IF; END IF;
...@@ -53,7 +53,7 @@ DECLARE ...@@ -53,7 +53,7 @@ DECLARE
__start_id INT; __start_id INT;
BEGIN BEGIN
__account_id = find_account_id( _account, True ); __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 IF __start_id <> 0 THEN
SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE follower = __account_id AND following = __start_id ); SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE follower = __account_id AND following = __start_id );
END IF; END IF;
......
...@@ -117,7 +117,7 @@ DECLARE __voter_id INT; ...@@ -117,7 +117,7 @@ DECLARE __voter_id INT;
DECLARE __post_id INT; DECLARE __post_id INT;
BEGIN 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 ); __post_id = find_comment_id( _AUTHOR, _PERMLINK, True );
RETURN QUERY RETURN QUERY
......
...@@ -228,7 +228,7 @@ IF NOT EXISTS(SELECT data_type FROM information_schema.columns ...@@ -228,7 +228,7 @@ IF NOT EXISTS(SELECT data_type FROM information_schema.columns
UPDATE hive_posts hp UPDATE hive_posts hp
SET SET
tags_ids = tags.tags tags_ids = tags.tags
FROM FROM
( (
SELECT SELECT
...@@ -237,7 +237,7 @@ IF NOT EXISTS(SELECT data_type FROM information_schema.columns ...@@ -237,7 +237,7 @@ IF NOT EXISTS(SELECT data_type FROM information_schema.columns
FROM FROM
hive_post_tags hpt hive_post_tags hpt
GROUP BY post_id GROUP BY post_id
) as tags ) as tags
WHERE hp.id = tags.post_id; WHERE hp.id = tags.post_id;
ELSE ELSE
RAISE NOTICE 'SKIPPING hive_posts upgrade - adding a tags_ids column'; RAISE NOTICE 'SKIPPING hive_posts upgrade - adding a tags_ids column';
......
...@@ -64,13 +64,15 @@ LANGUAGE 'plpgsql' ...@@ -64,13 +64,15 @@ LANGUAGE 'plpgsql'
AS AS
$function$ $function$
DECLARE DECLARE
account_id INT; __account_id INT = 0;
BEGIN BEGIN
SELECT INTO account_id COALESCE( ( SELECT id FROM hive_accounts WHERE name=_account ), 0 ); IF (_account <> '') THEN
IF _check AND account_id = 0 THEN SELECT INTO __account_id COALESCE( ( SELECT id FROM hive_accounts WHERE name=_account ), 0 );
RAISE EXCEPTION 'Account % does not exist', _account; IF _check AND __account_id = 0 THEN
RAISE EXCEPTION 'Account % does not exist', _account;
END IF;
END IF; END IF;
RETURN account_id; RETURN __account_id;
END END
$function$ $function$
; ;
...@@ -13,20 +13,19 @@ from hive.server.common.mutes import Mutes ...@@ -13,20 +13,19 @@ from hive.server.common.mutes import Mutes
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@return_error_info @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.""" """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'] db = context['db']
author = valid_account(author) author = valid_account(author)
permlink = valid_permlink(permlink) permlink = valid_permlink(permlink)
observer = valid_account(observer, allow_empty=True)
blacklisted_for_user = None blacklisted_for_user = None
if observer: if observer:
blacklisted_for_user = await Mutes.get_blacklisted_for_observer(observer, context) 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) rows = await db.query_all(sql, author=author, permlink=permlink, observer=observer)
if not rows or len(rows) == 0: if not rows or len(rows) == 0:
return {} return {}
......
...@@ -237,7 +237,7 @@ async def _child_ids(db, parent_ids): ...@@ -237,7 +237,7 @@ async def _child_ids(db, parent_ids):
async def _load_discussion(db, author, permlink, observer=None): async def _load_discussion(db, author, permlink, observer=None):
"""Load a full discussion thread.""" """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) sql_result = await db.query_all(sql, author=author, permlink=permlink, observer=observer)
muted_accounts = Mutes.all() muted_accounts = Mutes.all()
......
...@@ -693,7 +693,7 @@ ...@@ -693,7 +693,7 @@
"spaminator" "spaminator"
], ],
"id": "follow", "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\"]}]"
} }
}, },
{ {
......
Subproject commit 88c50bc23cece0e6ba9a80018d689a3eeea27e18 Subproject commit 87c4457827200ef54f8fe64f942df641a9f1b1af
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