diff --git a/hive/indexer/blocks.py b/hive/indexer/blocks.py index 8f2f89ef2d8b68ce0c1447357709184b2e7686e5..d4ba4ef9dab4c87450f0e13f364afae5b7d5b55c 100644 --- a/hive/indexer/blocks.py +++ b/hive/indexer/blocks.py @@ -101,9 +101,10 @@ class Blocks: return cls.ops_stats @staticmethod - def prepare_vops(vopsList, date): + def prepare_vops( comment_payout_ops, vopsList, date): vote_ops = {} - comment_payout_ops = {} + + ops_stats = { 'author_reward_operation' : 0, 'comment_reward_operation' : 0, 'effective_comment_vote_operation' : 0, 'comment_payout_update_operation' : 0 } for vop in vopsList: key = None @@ -111,47 +112,46 @@ class Blocks: op_type = vop['type'] op_value = vop['value'] + key = "{}/{}".format(op_value['author'], op_value['permlink']) if op_type == 'author_reward_operation': - key = "{}/{}".format(op_value['author'], op_value['permlink']) + ops_stats[ 'author_reward_operation' ] += 1 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, 'date' : date } comment_payout_ops[key][op_type] = op_value elif op_type == 'comment_reward_operation': - key = "{}/{}".format(op_value['author'], op_value['permlink']) + ops_stats[ 'comment_reward_operation' ] += 1 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, 'date' : date } comment_payout_ops[key]['effective_comment_vote_operation'] = None comment_payout_ops[key][op_type] = op_value elif op_type == 'effective_comment_vote_operation': - - key = "{}/{}".format(op_value['author'], op_value['permlink']) + ops_stats[ 'effective_comment_vote_operation' ] += 1 key_vote = "{}/{}/{}".format(op_value['voter'], op_value['author'], op_value['permlink']) 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, 'date' : date } comment_payout_ops[key][op_type] = op_value vote_ops[ key_vote ] = op_value elif op_type == 'comment_payout_update_operation': - - key = "{}/{}".format(op_value['author'], op_value['permlink']) + ops_stats[ 'comment_payout_update_operation' ] += 1 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, 'date' : date } comment_payout_ops[key][op_type] = op_value - return (vote_ops, comment_payout_ops) + return (vote_ops, ops_stats) @classmethod @@ -235,24 +235,21 @@ class Blocks: cls.ops_stats = Blocks.merge_ops_stats(cls.ops_stats, custom_ops_stats) # virtual ops - comment_payout_ops = {} + comment_payout_stats = {} vote_ops = {} - empty_vops = (vote_ops, comment_payout_ops) + empty_vops = (vote_ops, comment_payout_stats) if is_initial_sync: - (vote_ops, comment_payout_ops) = virtual_operations[num] if num in virtual_operations else empty_vops + (vote_ops, comment_payout_stats) = virtual_operations[num] if num in virtual_operations else empty_vops else: vops = hived.get_virtual_operations(num) - (vote_ops, comment_payout_ops) = Blocks.prepare_vops(vops, cls._head_block_date) + (vote_ops, comment_payout_stats) = Blocks.prepare_vops(Posts.comment_payout_ops, vops, cls._head_block_date) + cls.ops_stats = Blocks.merge_ops_stats(cls.ops_stats, comment_payout_stats) 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) - cls.ops_stats = Blocks.merge_ops_stats(cls.ops_stats, comment_payout_stats) - cls._head_block_date = block_date return num diff --git a/hive/indexer/posts.py b/hive/indexer/posts.py index 855483a0970414d4f391837c0ba6242a0d504568..50be0ea833b9b1da03b1874f810b5aa7f1b07b5a 100644 --- a/hive/indexer/posts.py +++ b/hive/indexer/posts.py @@ -30,6 +30,7 @@ class Posts: _hits = 0 _miss = 0 + comment_payout_ops = {} _comment_payout_ops = [] @classmethod @@ -148,7 +149,7 @@ class Posts: cls._insert_feed_cache(result, block_date) @classmethod - def flush(cls): + def flush_into_db(cls): sql = """ UPDATE hive_posts AS ihp SET total_payout_value = COALESCE( data_source.total_payout_value, ihp.total_payout_value ), @@ -219,13 +220,11 @@ class Posts: cls._comment_payout_ops.clear() @classmethod - def comment_payout_op(cls, ops, date): + def comment_payout_op(cls): values_limit = 1000 - ops_stats = { 'author_reward_operation' : 0, 'comment_reward_operation' : 0, 'effective_comment_vote_operation' : 0, 'comment_payout_update_operation' : 0 } - """ Process comment payment operations """ - for k, v in ops.items(): + for k, v in cls.comment_payout_ops.items(): author = None permlink = None @@ -251,9 +250,10 @@ class Posts: is_paidout = None + date = v[ 'date' ] + if v[ 'author_reward_operation' ] is not None: value = v[ 'author_reward_operation' ] - ops_stats[ 'author_reward_operation' ] += 1 author_rewards_hive = value['hive_payout']['amount'] author_rewards_hbd = value['hbd_payout']['amount'] author_rewards_vests = value['vesting_payout']['amount'] @@ -264,7 +264,6 @@ class Posts: if v[ 'comment_reward_operation' ] is not None: value = v[ 'comment_reward_operation' ] - ops_stats[ 'comment_reward_operation' ] += 1 comment_author_reward = value['payout'] author_rewards = value['author_rewards'] total_payout_value = value['total_payout_value'] @@ -280,7 +279,6 @@ class Posts: if v[ 'effective_comment_vote_operation' ] is not None: value = v[ 'effective_comment_vote_operation' ] - ops_stats[ 'effective_comment_vote_operation' ] += 1 pending_payout = sbd_amount( value['pending_payout'] ) if author is None: author = value['author'] @@ -288,7 +286,6 @@ class Posts: if v[ 'comment_payout_update_operation' ] is not None: value = v[ 'comment_payout_update_operation' ] - ops_stats[ 'comment_payout_update_operation' ] += 1 is_paidout = True if author is None: author = value['author'] @@ -323,8 +320,6 @@ class Posts: "NULL" if ( is_paidout is None ) else is_paidout )) - return ops_stats - @classmethod def update_child_count(cls, child_id, op='+'): """ Increase/decrease child count by 1 """ @@ -453,3 +448,8 @@ class Posts: new_body = new_body_def return new_body + + @classmethod + def flush(cls): + cls.comment_payout_op() + cls.flush_into_db() diff --git a/hive/indexer/sync.py b/hive/indexer/sync.py index 806f71844592aab7f55497cd0978e34431610776..878aea039ded566c265d91c1c7bb14495385ebe0 100644 --- a/hive/indexer/sync.py +++ b/hive/indexer/sync.py @@ -19,6 +19,7 @@ from hive.db.db_state import DbState from hive.utils.timer import Timer from hive.steem.block.stream import MicroForkException +from hive.indexer.posts import Posts from hive.indexer.blocks import Blocks from hive.indexer.accounts import Accounts from hive.indexer.feed_cache import FeedCache @@ -45,7 +46,7 @@ def prepare_vops(vops_by_block): for blockNum, blockDict in vops_by_block.items(): vopsList = blockDict['ops'] date = blockDict['timestamp'] - preparedVops[blockNum] = Blocks.prepare_vops(vopsList, date) + preparedVops[blockNum] = Blocks.prepare_vops(Posts.comment_payout_ops, vopsList, date) return preparedVops diff --git a/hive/indexer/votes.py b/hive/indexer/votes.py index 31683ea3193b3fc6dd036fa01618d88ae1a45f64..bfff862d60d828e63f7f268e8b3d529843da7230 100644 --- a/hive/indexer/votes.py +++ b/hive/indexer/votes.py @@ -83,10 +83,12 @@ class Votes: key = voter + "/" + author + "/" + permlink assert key in cls._votes_data + log.info( "xx {}".format(vop) ) + 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"] + cls._votes_data[key]["last_update"] = date @classmethod def flush(cls):