Skip to content
Snippets Groups Projects
Commit c42963fe authored by Mariusz Trela's avatar Mariusz Trela
Browse files

The call `database_api.find_votes` works

parent f8f5ba06
No related branches found
No related tags found
4 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!138Small typos fixed,!129The calls 'list_votes'/'find_votes' work
This commit is part of merge request !129. Comments created here will be created in the context of that merge request.
...@@ -109,7 +109,7 @@ async def get_post(context, author, permlink, observer=None): ...@@ -109,7 +109,7 @@ async def get_post(context, author, permlink, observer=None):
result = await db.query_all(sql, author=author, permlink=permlink) result = await db.query_all(sql, author=author, permlink=permlink)
assert len(result) == 1, 'invalid author/permlink or post not found in cache' assert len(result) == 1, 'invalid author/permlink or post not found in cache'
post = _bridge_post_object(result[0]) 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) post = await append_statistics_to_post(post, result[0], False, blacklists_for_user)
return post return post
...@@ -213,7 +213,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', ...@@ -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) 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: for row in pinned_result:
post = _bridge_post_object(row) 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) post = await append_statistics_to_post(post, row, True, blacklists_for_user)
limit = limit - 1 limit = limit - 1
posts.append(post) posts.append(post)
...@@ -222,7 +222,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', ...@@ -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) 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: for row in sql_result:
post = _bridge_post_object(row) 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) post = await append_statistics_to_post(post, row, False, blacklists_for_user)
if post['post_id'] in pinned_post_ids: if post['post_id'] in pinned_post_ids:
continue continue
...@@ -314,7 +314,7 @@ async def get_account_posts(context, sort, account, start_author='', start_perml ...@@ -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) sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit)
for row in sql_result: for row in sql_result:
post = _bridge_post_object(row) 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) post = await append_statistics_to_post(post, row, False, blacklists_for_user)
posts.append(post) posts.append(post)
return posts return posts
......
...@@ -100,7 +100,7 @@ async def load_posts_keyed(db, ids, truncate_body=0): ...@@ -100,7 +100,7 @@ async def load_posts_keyed(db, ids, truncate_body=0):
row['author_rep'] = author['reputation'] row['author_rep'] = author['reputation']
post = _bridge_post_object(row, truncate_body=truncate_body) 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']) post['blacklists'] = Mutes.lists(post['author'], author['reputation'])
......
...@@ -95,7 +95,7 @@ async def get_discussion(context, author, permlink, observer=None): ...@@ -95,7 +95,7 @@ async def get_discussion(context, author, permlink, observer=None):
root_id = rows[0]['id'] root_id = rows[0]['id']
all_posts = {} all_posts = {}
root_post = _bridge_post_object(rows[0]) 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 = await append_statistics_to_post(root_post, rows[0], False, blacklists_for_user)
root_post['replies'] = [] root_post['replies'] = []
all_posts[root_id] = root_post all_posts[root_id] = root_post
...@@ -108,7 +108,7 @@ async def get_discussion(context, author, permlink, observer=None): ...@@ -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] = []
parent_to_children_id_map[parent_id].append(rows[index]['id']) parent_to_children_id_map[parent_id].append(rows[index]['id'])
post = _bridge_post_object(rows[index]) 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 = await append_statistics_to_post(post, rows[index], False, blacklists_for_user)
post['replies'] = [] post['replies'] = []
all_posts[post['post_id']] = post all_posts[post['post_id']] = post
......
...@@ -154,7 +154,7 @@ async def get_content(context, author: str, permlink: str, observer=None): ...@@ -154,7 +154,7 @@ async def get_content(context, author: str, permlink: str, observer=None):
if result: if result:
result = dict(result[0]) result = dict(result[0])
post = _condenser_post_object(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: if not observer:
post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all()) post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all())
else: else:
...@@ -272,7 +272,7 @@ async def get_discussions_by(discussion_type, context, start_author: str = '', ...@@ -272,7 +272,7 @@ async def get_discussions_by(discussion_type, context, start_author: str = '',
posts = [] posts = []
for row in result: for row in result:
post = _condenser_post_object(row, truncate_body) 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()) post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all())
posts.append(post) posts.append(post)
#posts = await resultset_to_posts(db=db, resultset=result, truncate_body=truncate_body) #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 = ...@@ -381,7 +381,7 @@ async def get_discussions_by_blog(context, tag: str = None, start_author: str =
for row in result: for row in result:
row = dict(row) row = dict(row)
post = _condenser_post_object(row, truncate_body=truncate_body) 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()) post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all())
#posts_by_id[row['post_id']] = post #posts_by_id[row['post_id']] = post
posts_by_id.append(post) posts_by_id.append(post)
...@@ -439,7 +439,7 @@ async def get_discussions_by_comments(context, start_author: str = None, start_p ...@@ -439,7 +439,7 @@ async def get_discussions_by_comments(context, start_author: str = None, start_p
for row in result: for row in result:
row = dict(row) row = dict(row)
post = _condenser_post_object(row, truncate_body=truncate_body) 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()) post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all())
posts.append(post) posts.append(post)
...@@ -592,4 +592,4 @@ async def get_active_votes(context, author: str, permlink: str): ...@@ -592,4 +592,4 @@ async def get_active_votes(context, author: str, permlink: str):
valid_permlink(permlink) valid_permlink(permlink)
db = context['db'] 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 )
...@@ -89,7 +89,7 @@ async def load_posts_keyed(db, ids, truncate_body=0): ...@@ -89,7 +89,7 @@ async def load_posts_keyed(db, ids, truncate_body=0):
row['author_rep'] = author_reps[row['author']] row['author_rep'] = author_reps[row['author']]
post = _condenser_post_object(row, truncate_body=truncate_body) 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 posts_by_id[row['id']] = post
return posts_by_id return posts_by_id
...@@ -139,7 +139,7 @@ async def resultset_to_posts(db, resultset, truncate_body=0): ...@@ -139,7 +139,7 @@ async def resultset_to_posts(db, resultset, truncate_body=0):
row = dict(row) row = dict(row)
row['author_rep'] = author_reps[row['author']] row['author_rep'] = author_reps[row['author']]
post = _condenser_post_object(row, truncate_body=truncate_body) 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) posts.append(post)
return posts return posts
......
...@@ -168,10 +168,10 @@ class VotesPresentation(Enum): ...@@ -168,10 +168,10 @@ class VotesPresentation(Enum):
BridgeApi = 4 BridgeApi = 4
@return_error_info @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 """ """ Returns all votes for the given post """
valid_account(params['author']) valid_account(author)
valid_permlink(params['permlink']) valid_permlink(permlink)
db = context['db'] db = context['db']
sql = """ sql = """
SELECT SELECT
...@@ -193,7 +193,7 @@ async def find_votes(context, params: dict, votes_presentation = VotesPresentati ...@@ -193,7 +193,7 @@ async def find_votes(context, params: dict, votes_presentation = VotesPresentati
""" """
ret = [] 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: for row in rows:
if votes_presentation == VotesPresentation.DatabaseApi: if votes_presentation == VotesPresentation.DatabaseApi:
......
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