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

Avoiding a redundant loop during `effective_comment_vote_operation` processing

parent 3bd73fbc
No related branches found
No related tags found
5 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!138Small typos fixed,!135Enable postgres monitoring on CI server,!116Avoiding a redundant loop during `effective_comment_vote_operation` processing
...@@ -116,8 +116,6 @@ class Blocks: ...@@ -116,8 +116,6 @@ class Blocks:
@staticmethod @staticmethod
def prepare_vops(comment_payout_ops, vopsList, date, block_num): def prepare_vops(comment_payout_ops, vopsList, date, block_num):
vote_ops = {}
ineffective_deleted_ops = {} ineffective_deleted_ops = {}
registered_ops_stats = [ 'author_reward_operation', 'comment_reward_operation', 'effective_comment_vote_operation', 'comment_payout_update_operation', 'ineffective_delete_comment_operation'] registered_ops_stats = [ 'author_reward_operation', 'comment_reward_operation', 'effective_comment_vote_operation', 'comment_payout_update_operation', 'ineffective_delete_comment_operation']
...@@ -146,8 +144,7 @@ class Blocks: ...@@ -146,8 +144,7 @@ class Blocks:
comment_payout_ops[key][op_type] = ( op_value, date ) comment_payout_ops[key][op_type] = ( op_value, date )
elif op_type == 'effective_comment_vote_operation': elif op_type == 'effective_comment_vote_operation':
key_vote = "{}/{}/{}".format(op_value['voter'], op_value['author'], op_value['permlink']) Votes.effective_comment_vote_op( op_value )
vote_ops[ key_vote ] = op_value
if key not in comment_payout_ops: if key not in comment_payout_ops:
comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None } comment_payout_ops[key] = { 'author_reward_operation':None, 'comment_reward_operation':None, 'effective_comment_vote_operation':None, 'comment_payout_update_operation':None }
...@@ -166,7 +163,7 @@ class Blocks: ...@@ -166,7 +163,7 @@ class Blocks:
if op_type in registered_ops_stats: if op_type in registered_ops_stats:
OPSM.op_stats(op_type, OPSM.stop(start)) OPSM.op_stats(op_type, OPSM.stop(start))
return (vote_ops, ineffective_deleted_ops) return ineffective_deleted_ops
@classmethod @classmethod
...@@ -184,16 +181,15 @@ class Blocks: ...@@ -184,16 +181,15 @@ class Blocks:
if cls._head_block_date is None: if cls._head_block_date is None:
cls._head_block_date = cls._current_block_date cls._head_block_date = cls._current_block_date
vote_ops = None
comment_payout_stats = None comment_payout_stats = None
ineffective_deleted_ops = None ineffective_deleted_ops = None
if is_initial_sync: if is_initial_sync:
if num in virtual_operations: if num in virtual_operations:
(vote_ops, ineffective_deleted_ops ) = Blocks.prepare_vops(Posts.comment_payout_ops, virtual_operations[num], cls._current_block_date, num) ineffective_deleted_ops = Blocks.prepare_vops(Posts.comment_payout_ops, virtual_operations[num], cls._current_block_date, num)
else: else:
vops = hived.get_virtual_operations(num) vops = hived.get_virtual_operations(num)
(vote_ops, ineffective_deleted_ops ) = Blocks.prepare_vops(Posts.comment_payout_ops, vops, cls._current_block_date, num) ineffective_deleted_ops = Blocks.prepare_vops(Posts.comment_payout_ops, vops, cls._current_block_date, num)
json_ops = [] json_ops = []
for tx_idx, tx in enumerate(block['transactions']): for tx_idx, tx in enumerate(block['transactions']):
...@@ -258,10 +254,6 @@ class Blocks: ...@@ -258,10 +254,6 @@ class Blocks:
if json_ops: if json_ops:
CustomOp.process_ops(json_ops, num, cls._head_block_date) CustomOp.process_ops(json_ops, num, cls._head_block_date)
if vote_ops is not None:
for k, v in vote_ops.items():
Votes.effective_comment_vote_op(k, v)
cls._head_block_date = cls._current_block_date cls._head_block_date = cls._current_block_date
return num return num
......
...@@ -27,12 +27,11 @@ class Votes: ...@@ -27,12 +27,11 @@ class Votes:
log.exception("Adding new vote-info into '_votes_data' dict") log.exception("Adding new vote-info into '_votes_data' dict")
raise RuntimeError("Fatal error") raise RuntimeError("Fatal error")
key = voter + "/" + author + "/" + permlink key = "{}/{}/{}".format(voter, author, permlink)
if key in cls._votes_data: if key in cls._votes_data:
cls._votes_data[key]["vote_percent"] = weight cls._votes_data[key]["vote_percent"] = weight
cls._votes_data[key]["last_update"] = date cls._votes_data[key]["last_update"] = date
cls._votes_data[key]["block_num"] = block_num
else: else:
cls._votes_data[key] = dict(voter=voter, cls._votes_data[key] = dict(voter=voter,
author=author, author=author,
...@@ -45,20 +44,26 @@ class Votes: ...@@ -45,20 +44,26 @@ class Votes:
block_num=block_num) block_num=block_num)
@classmethod @classmethod
def effective_comment_vote_op(cls, key, vop): def effective_comment_vote_op(cls, vop):
""" Process effective_comment_vote_operation """ """ Process effective_comment_vote_operation """
if cls.inside_flush: key = "{}/{}/{}".format(vop['voter'], vop['author'], vop['permlink'])
log.exception("Updating data in '_votes_data' using effective comment")
raise RuntimeError("Fatal error")
assert key in cls._votes_data
cls._votes_data[key]["weight"] = vop["weight"]
cls._votes_data[key]["rshares"] = vop["rshares"]
cls._votes_data[key]["is_effective"] = True
cls._votes_data[key]["block_num"] = vop['block_num']
if key in cls._votes_data:
cls._votes_data[key]["weight"] = vop["weight"]
cls._votes_data[key]["rshares"] = vop["rshares"]
cls._votes_data[key]["is_effective"] = True
cls._votes_data[key]["block_num"] = vop['block_num']
else:
cls._votes_data[key] = dict(voter=vop['voter'],
author=vop['author'],
permlink=vop['permlink'],
vote_percent=0,
weight=vop["weight"],
rshares=vop["rshares"],
last_update='1970-01-01 00:00:00',
is_effective=True,
block_num=vop['block_num'])
@classmethod @classmethod
def flush(cls): def flush(cls):
""" Flush vote data from cache to database """ """ Flush vote data from cache to database """
......
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