From c42963fe24b59559cacd0c4a5a48c03c9a52c4fa Mon Sep 17 00:00:00 2001 From: mtrela <mtrela@syncad.com> Date: Thu, 3 Sep 2020 12:02:39 +0200 Subject: [PATCH] The call `database_api.find_votes` works --- hive/server/bridge_api/methods.py | 8 ++++---- hive/server/bridge_api/objects.py | 2 +- hive/server/bridge_api/thread.py | 4 ++-- hive/server/condenser_api/methods.py | 10 +++++----- hive/server/condenser_api/objects.py | 4 ++-- hive/server/database_api/methods.py | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py index 913459495..aa47254af 100644 --- a/hive/server/bridge_api/methods.py +++ b/hive/server/bridge_api/methods.py @@ -109,7 +109,7 @@ async def get_post(context, author, permlink, observer=None): result = await db.query_all(sql, author=author, permlink=permlink) assert len(result) == 1, 'invalid author/permlink or post not found in cache' post = _bridge_post_object(result[0]) - post['active_votes'] = await find_votes({'db':db}, {'author':author, 'permlink':permlink}, VotesPresentation.BridgeApi) + post['active_votes'] = await find_votes({'db':db}, author, permlink, VotesPresentation.BridgeApi) post = await append_statistics_to_post(post, result[0], False, blacklists_for_user) return post @@ -213,7 +213,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', pinned_result = await db.query_all(pinned_sql, author=start_author, limit=limit, tag=tag, permlink=start_permlink, community_name=tag, observer=observer) for row in pinned_result: post = _bridge_post_object(row) - post['active_votes'] = await find_votes({'db':db}, {'author':row['author'], 'permlink':row['permlink']}, VotesPresentation.BridgeApi) + post['active_votes'] = await find_votes({'db':db}, row['author'], row['permlink'], VotesPresentation.BridgeApi) post = await append_statistics_to_post(post, row, True, blacklists_for_user) limit = limit - 1 posts.append(post) @@ -222,7 +222,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', sql_result = await db.query_all(sql, author=start_author, limit=limit, tag=tag, permlink=start_permlink, community_name=tag, observer=observer) for row in sql_result: post = _bridge_post_object(row) - post['active_votes'] = await find_votes({'db':db}, {'author':row['author'], 'permlink':row['permlink']}, VotesPresentation.BridgeApi) + post['active_votes'] = await find_votes({'db':db}, row['author'], row['permlink'], VotesPresentation.BridgeApi) post = await append_statistics_to_post(post, row, False, blacklists_for_user) if post['post_id'] in pinned_post_ids: continue @@ -314,7 +314,7 @@ async def get_account_posts(context, sort, account, start_author='', start_perml sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit) for row in sql_result: post = _bridge_post_object(row) - post['active_votes'] = await find_votes({'db':db}, {'author':row['author'], 'permlink':row['permlink']}, VotesPresentation.BridgeApi) + post['active_votes'] = await find_votes({'db':db}, row['author'], row['permlink'], VotesPresentation.BridgeApi) post = await append_statistics_to_post(post, row, False, blacklists_for_user) posts.append(post) return posts diff --git a/hive/server/bridge_api/objects.py b/hive/server/bridge_api/objects.py index c99adcfd9..e7d7e20d6 100644 --- a/hive/server/bridge_api/objects.py +++ b/hive/server/bridge_api/objects.py @@ -100,7 +100,7 @@ async def load_posts_keyed(db, ids, truncate_body=0): row['author_rep'] = author['reputation'] post = _bridge_post_object(row, truncate_body=truncate_body) - post['active_votes'] = await find_votes({'db':db}, {'author':row['author'], 'permlink':row['permlink']}, VotesPresentation.BridgeApi) + post['active_votes'] = await find_votes({'db':db}, row['author'], row['permlink'], VotesPresentation.BridgeApi) post['blacklists'] = Mutes.lists(post['author'], author['reputation']) diff --git a/hive/server/bridge_api/thread.py b/hive/server/bridge_api/thread.py index 4145983e2..af8f07e19 100644 --- a/hive/server/bridge_api/thread.py +++ b/hive/server/bridge_api/thread.py @@ -95,7 +95,7 @@ async def get_discussion(context, author, permlink, observer=None): root_id = rows[0]['id'] all_posts = {} root_post = _bridge_post_object(rows[0]) - root_post['active_votes'] = await find_votes({'db':db}, {'author':rows[0]['author'], 'permlink':rows[0]['permlink']}, VotesPresentation.BridgeApi) + root_post['active_votes'] = await find_votes({'db':db}, rows[0]['author'], rows[0]['permlink'], VotesPresentation.BridgeApi) root_post = await append_statistics_to_post(root_post, rows[0], False, blacklists_for_user) root_post['replies'] = [] all_posts[root_id] = root_post @@ -108,7 +108,7 @@ async def get_discussion(context, author, permlink, observer=None): parent_to_children_id_map[parent_id] = [] parent_to_children_id_map[parent_id].append(rows[index]['id']) post = _bridge_post_object(rows[index]) - post['active_votes'] = await find_votes({'db':db}, {'author':rows[index]['author'], 'permlink':rows[index]['permlink']}, VotesPresentation.BridgeApi) + post['active_votes'] = await find_votes({'db':db}, rows[index]['author'], rows[index]['permlink'], VotesPresentation.BridgeApi) post = await append_statistics_to_post(post, rows[index], False, blacklists_for_user) post['replies'] = [] all_posts[post['post_id']] = post diff --git a/hive/server/condenser_api/methods.py b/hive/server/condenser_api/methods.py index b4bbdb459..56b1ed3e9 100644 --- a/hive/server/condenser_api/methods.py +++ b/hive/server/condenser_api/methods.py @@ -154,7 +154,7 @@ async def get_content(context, author: str, permlink: str, observer=None): if result: result = dict(result[0]) post = _condenser_post_object(result, 0) - post['active_votes'] = await find_votes(context, {'author':author, 'permlink':permlink}, VotesPresentation.CondenserApi) + post['active_votes'] = await find_votes(context, author, permlink, VotesPresentation.CondenserApi) if not observer: post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all()) else: @@ -272,7 +272,7 @@ async def get_discussions_by(discussion_type, context, start_author: str = '', posts = [] for row in result: post = _condenser_post_object(row, truncate_body) - post['active_votes'] = await find_votes(context, {'author':post['author'], 'permlink':post['permlink']}) + post['active_votes'] = await find_votes(context, post['author'], post['permlink']) post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all()) posts.append(post) #posts = await resultset_to_posts(db=db, resultset=result, truncate_body=truncate_body) @@ -381,7 +381,7 @@ async def get_discussions_by_blog(context, tag: str = None, start_author: str = for row in result: row = dict(row) post = _condenser_post_object(row, truncate_body=truncate_body) - post['active_votes'] = await find_votes(context, {'author':post['author'], 'permlink':post['permlink']}, votes_presentation = VotesPresentation.CondenserApi) + post['active_votes'] = await find_votes(context, post['author'], post['permlink'], votes_presentation = VotesPresentation.CondenserApi) post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all()) #posts_by_id[row['post_id']] = post posts_by_id.append(post) @@ -439,7 +439,7 @@ async def get_discussions_by_comments(context, start_author: str = None, start_p for row in result: row = dict(row) post = _condenser_post_object(row, truncate_body=truncate_body) - post['active_votes'] = await find_votes(context, {'author':post['author'], 'permlink':post['permlink']}, VotesPresentation.CondenserApi) + post['active_votes'] = await find_votes(context, post['author'], post['permlink'], VotesPresentation.CondenserApi) post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all()) posts.append(post) @@ -592,4 +592,4 @@ async def get_active_votes(context, author: str, permlink: str): valid_permlink(permlink) db = context['db'] - return await find_votes( {'db':db}, {'author':author, 'permlink':permlink}, VotesPresentation.ActiveVotes ) + return await find_votes( {'db':db}, author, permlink, VotesPresentation.ActiveVotes ) diff --git a/hive/server/condenser_api/objects.py b/hive/server/condenser_api/objects.py index ca231cc1d..37a040aa6 100644 --- a/hive/server/condenser_api/objects.py +++ b/hive/server/condenser_api/objects.py @@ -89,7 +89,7 @@ async def load_posts_keyed(db, ids, truncate_body=0): row['author_rep'] = author_reps[row['author']] post = _condenser_post_object(row, truncate_body=truncate_body) - post['active_votes'] = await find_votes({'db':db}, {'author':row['author'], 'permlink':row['permlink']}, VotesPresentation.CondenserApi) + post['active_votes'] = await find_votes({'db':db}, row['author'], row['permlink'], VotesPresentation.CondenserApi) posts_by_id[row['id']] = post return posts_by_id @@ -139,7 +139,7 @@ async def resultset_to_posts(db, resultset, truncate_body=0): row = dict(row) row['author_rep'] = author_reps[row['author']] post = _condenser_post_object(row, truncate_body=truncate_body) - post['active_votes'] = await find_votes({'db':db}, {'author':row['author'], 'permlink':row['permlink']}, VotesPresentation.CondenserApi) + post['active_votes'] = await find_votes({'db':db}, row['author'], row['permlink'], VotesPresentation.CondenserApi) posts.append(post) return posts diff --git a/hive/server/database_api/methods.py b/hive/server/database_api/methods.py index e9d3d991d..71a737304 100644 --- a/hive/server/database_api/methods.py +++ b/hive/server/database_api/methods.py @@ -168,10 +168,10 @@ class VotesPresentation(Enum): BridgeApi = 4 @return_error_info -async def find_votes(context, params: dict, votes_presentation = VotesPresentation.DatabaseApi): +async def find_votes(context, author: str, permlink: str, votes_presentation = VotesPresentation.DatabaseApi): """ Returns all votes for the given post """ - valid_account(params['author']) - valid_permlink(params['permlink']) + valid_account(author) + valid_permlink(permlink) db = context['db'] sql = """ SELECT @@ -193,7 +193,7 @@ async def find_votes(context, params: dict, votes_presentation = VotesPresentati """ ret = [] - rows = await db.query_all(sql, author=params['author'], permlink=params['permlink']) + rows = await db.query_all(sql, author=author, permlink=permlink) for row in rows: if votes_presentation == VotesPresentation.DatabaseApi: -- GitLab