Skip to content
Snippets Groups Projects

Draft: refactor follows and update_nofications indexing

Open Dan Notestein requested to merge 267-update-notification-cache into develop
1 file
+ 2
1
Compare changes
  • Side-by-side
  • Inline
+ 15
28
@@ -179,7 +179,8 @@ class Blocks:
def flush_data_in_1_thread(cls) -> None:
for description, f, c in cls._concurrent_flush:
try:
f()
(n, elapsedTime) = time_collector(f)
log.info("%s flush executed in: %.4f s", description, elapsedTime)
except Exception as exc:
log.error(f'{description!r} generated an exception: {exc}')
raise exc
@@ -346,7 +347,12 @@ class Blocks:
Posts.comment_payout_ops, block, cls._current_block_date, num, num <= cls._last_safe_cashout_block
)
json_ops = []
def try_register_account(account_name, op, op_details):
if not Accounts.register(
account_name, op_details, cls._head_block_date, num
):
log.error(f"Failed to register account {account_name} from operation: {op}")
for transaction in block.get_next_transaction():
assert issubclass(type(transaction), Transaction)
for operation in transaction.get_next_operation():
@@ -365,36 +371,20 @@ class Blocks:
assert 'block_num' not in op
op['block_num'] = num
account_name = None
op_details = None
potentially_new_account = False
# account ops
if op_type == OperationType.POW:
account_name = op['worker_account']
potentially_new_account = True
try_register_account(op['worker_account'], op, None)
elif op_type == OperationType.POW_2:
account_name = op['work']['value']['input']['worker_account']
potentially_new_account = True
try_register_account(op['work']['value']['input']['worker_account'], op, None)
elif op_type == OperationType.ACCOUNT_CREATE:
account_name = op['new_account_name']
op_details = op
potentially_new_account = True
try_register_account(op['new_account_name'], op, op)
elif op_type == OperationType.ACCOUNT_CREATE_WITH_DELEGATION:
account_name = op['new_account_name']
op_details = op
potentially_new_account = True
try_register_account(op['new_account_name'], op, op)
elif op_type == OperationType.CREATE_CLAIMED_ACCOUNT:
account_name = op['new_account_name']
op_details = op
potentially_new_account = True
if potentially_new_account and not Accounts.register(
account_name, op_details, cls._head_block_date, num
):
log.error(f"Failed to register account {account_name} from operation: {op}")
try_register_account(op['new_account_name'], op, op)
# account metadata updates
if op_type == OperationType.ACCOUNT_UPDATE:
elif op_type == OperationType.ACCOUNT_UPDATE:
Accounts.update_op(op, False)
elif op_type == OperationType.ACCOUNT_UPDATE_2:
Accounts.update_op(op, True)
@@ -427,17 +417,14 @@ class Blocks:
"""Is invoked when processing of block range is done and received
informations from hived are already stored in db
"""
is_hour_action = block_number % 1200 == 0
queries = [
f"SELECT {SCHEMA_NAME}.update_posts_rshares({block_number}, {block_number})",
f"SELECT {SCHEMA_NAME}.update_hive_posts_children_count({block_number}, {block_number})",
f"SELECT {SCHEMA_NAME}.update_hive_posts_root_id({block_number},{block_number})",
f"SELECT {SCHEMA_NAME}.update_feed_cache({block_number}, {block_number})",
f"SELECT {SCHEMA_NAME}.update_hive_posts_mentions({block_number}, {block_number})",
f"SELECT {SCHEMA_NAME}.update_notification_cache({block_number}, {block_number}, {is_hour_action})",
f"SELECT {SCHEMA_NAME}.update_follow_count({block_number}, {block_number})",
f"SELECT {SCHEMA_NAME}.update_last_completed_block({block_number})",
f"SELECT {SCHEMA_NAME}.prune_notification_cache({block_number})",
]
for query in queries:
Loading