diff --git a/hive/indexer/blocks.py b/hive/indexer/blocks.py index e1558f0fbe3a31348a05de40d56a4618e5cb0a56..e719f8fd3c17a68e9211c9c35dc56af4f018567e 100644 --- a/hive/indexer/blocks.py +++ b/hive/indexer/blocks.py @@ -99,7 +99,7 @@ class Blocks: @staticmethod def prepare_vops(vopsList, date): - vote_ops = [] + vote_ops = {} comment_payout_ops = {} for vop in vopsList: key = None @@ -119,7 +119,8 @@ class Blocks: key = "{}/{}".format(op_value['author'], op_value['permlink']) val = {'payout':op_value['payout'], 'author_rewards':op_value['author_rewards']} elif op_type == 'effective_comment_vote_operation': - vote_ops.append(vop) + key_vote = "{}/{}/{}".format(op_value['voter'], op_value['author'], op_value['permlink']) + vote_ops[ key_vote ] = op_value if key is not None and val is not None: if key in comment_payout_ops: @@ -199,6 +200,7 @@ class Blocks: Accounts.dirty(op['author']) # lite - rep Accounts.dirty(op['voter']) # lite - stats update_comment_pending_payouts.append([op['author'], op['permlink']]) + Votes.vote_op(op) # misc ops elif op_type == 'transfer_operation': @@ -217,7 +219,7 @@ class Blocks: # virtual ops comment_payout_ops = {} - vote_ops = [] + vote_ops = {} empty_vops = (vote_ops, comment_payout_ops) @@ -227,14 +229,8 @@ class Blocks: vops = hived.get_virtual_operations(num) (vote_ops, comment_payout_ops) = Blocks.prepare_vops(vops, cls._head_block_date) - for v in vote_ops: - Votes.vote_op(v, cls._head_block_date) - op_type = v['type'] - if op_type in cls.ops_stats: - cls.ops_stats[op_type] += 1 - else: - cls.ops_stats[op_type] = 1 - + for k, v in vote_ops.items(): + Votes.effective_comment_vote_op(v, cls._head_block_date) if comment_payout_ops: comment_payout_stats = Posts.comment_payout_op(comment_payout_ops, cls._head_block_date) diff --git a/hive/indexer/votes.py b/hive/indexer/votes.py index 6451a1e347d42d6ea2cf9c144ad16620562717a9..99ad38aac8c26bd8c03ee3ebf94567ec982b8280 100644 --- a/hive/indexer/votes.py +++ b/hive/indexer/votes.py @@ -55,14 +55,14 @@ class Votes: inside_flush = False @classmethod - def vote_op(cls, vop, date): + def vote_op(cls, vop): """ Process vote_operation """ - voter = vop['value']['voter'] - author = vop['value']['author'] - permlink = vop['value']['permlink'] + voter = vop['voter'] + author = vop['author'] + permlink = vop['permlink'] if(cls.inside_flush): - log.info("Adding new vote-info into _votes_data dict") + log.info("Adding new vote-info into '_votes_data' dict") raise "Fatal error" key = voter + "/" + author + "/" + permlink @@ -70,10 +70,29 @@ class Votes: cls._votes_data[key] = dict(voter=voter, author=author, permlink=permlink, - vote_percent=vop['value']['vote_percent'], - weight=vop['value']['weight'], - rshares=vop['value']['rshares'], - last_update=date) + vote_percent=0, + weight=0, + rshares=0, + last_update="1969-12-31T23:59:59") + + @classmethod + def effective_comment_vote_op(cls, vop, date): + """ Process effective_comment_vote_operation """ + voter = vop['voter'] + author = vop['author'] + permlink = vop['permlink'] + + if(cls.inside_flush): + log.info("Updating data in '_votes_data' using effective comment") + raise "Fatal error" + + key = voter + "/" + author + "/" + permlink + assert key in cls._votes_data + + cls._votes_data[key]["vote_percent"] = vop["vote_percent"] + cls._votes_data[key]["weight"] = vop["weight"] + cls._votes_data[key]["rshares"] = vop["rshares"] + cls._votes_data[key]["last_update"] = vop["last_update"] @classmethod def flush(cls): @@ -106,7 +125,7 @@ class Votes: vote_percent = EXCLUDED.vote_percent, last_update = EXCLUDED.last_update, num_changes = hive_votes.num_changes + 1 - WHERE hive_votes.id = EXCLUDED.id + WHERE hive_votes.voter_id = EXCLUDED.voter_id and hive_votes.author_id = EXCLUDED.author_id and hive_votes.permlink_id = EXCLUDED.permlink_id; """ values = []