diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py index 913459495f11bcd3b7ae2ab350b0a7ecbf4c15cf..aa47254afb214c96757be1b0b8e92c762f00b612 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 c99adcfd9d84cc946bbf230db388bab4dbfe8393..e7d7e20d68c90e4125f22ea24e10e693229574ba 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 4145983e23bc66caaa8d32b3189dc6e020afb728..af8f07e194cb83dab81d39e06bb1e9200c186f10 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 b4bbdb459f3aeaf2669f41679b155594a567ef69..56b1ed3e92d932bf1b7a34f3ae37bb466312bf17 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 ca231cc1d56fc29ce23e5479ffb7f7dd6dfb39c4..37a040aa6dcd70bfd13bc5eda8cb955a48be1b0b 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 e9d3d991d8a648ca3aa0604ceb3298f03c051896..71a737304d90791d451374086e1d0643faabc0ec 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: