Skip to content
Snippets Groups Projects
Commit c9499d1a authored by Tim's avatar Tim
Browse files

add progress bar, batch steemd blocks

parent d677bbed
No related branches found
No related tags found
No related merge requests found
import json import json
import logging import logging
import progressbar
from funcy.seqs import first, second, drop, flatten from funcy.seqs import first, second, drop, flatten
from hive.community.roles import get_user_role, privacy_map, permissions, is_permitted from hive.community.roles import get_user_role, privacy_map, permissions, is_permitted
...@@ -311,8 +312,8 @@ def process_block(block): ...@@ -311,8 +312,8 @@ def process_block(block):
# the FK constraint will then fail if we somehow end up on the wrong side in a fork reorg. # the FK constraint will then fail if we somehow end up on the wrong side in a fork reorg.
query("INSERT INTO hive_blocks (num, prev, txs, created_at) " query("INSERT INTO hive_blocks (num, prev, txs, created_at) "
"VALUES ('%d', '%d', '%d', '%s')" % (block_num, block_num - 1, len(txs), date)) "VALUES ('%d', '%d', '%d', '%s')" % (block_num, block_num - 1, len(txs), date))
if block_num % 1000 == 0: if block_num % 100000 == 0:
log.info("processing block {} at {} with {} txs".format(block_num, date, len(txs))) log.warning("processing block {} at {} with {} txs".format(block_num, date, len(txs)))
accounts = set() accounts = set()
comments = [] comments = []
...@@ -372,12 +373,16 @@ def process_blocks(blocks): ...@@ -372,12 +373,16 @@ def process_blocks(blocks):
def sync_from_file(file_path, chunk_size=250): def sync_from_file(file_path, chunk_size=250):
last_block = db_last_block() last_block = db_last_block()
bar = progressbar.ProgressBar(max_value = (10000000 - last_block))
progress = 0
with open(file_path) as f: with open(file_path) as f:
# each line in file represents one block # each line in file represents one block
# we can skip the blocks we already have # we can skip the blocks we already have
remaining = drop(last_block, f) remaining = drop(last_block, f)
for batch in partition_all(chunk_size, remaining): for batch in partition_all(chunk_size, remaining):
process_blocks(map(json.loads, batch)) process_blocks(map(json.loads, batch))
progress += chunk_size
bar.update(progress)
def sync_from_steemd(): def sync_from_steemd():
...@@ -386,8 +391,13 @@ def sync_from_steemd(): ...@@ -386,8 +391,13 @@ def sync_from_steemd():
start_block=db_last_block() + 1, start_block=db_last_block() + 1,
full_blocks=True, full_blocks=True,
) )
buffer = [] # TODO: only needed during resync
for block in h: for block in h:
process_blocks([block]) buffer.append(block)
if len(buffer) == 250:
process_blocks(buffer)
buffer = []
process_blocks(buffer)
# testing # testing
......
...@@ -36,9 +36,10 @@ setup( ...@@ -36,9 +36,10 @@ setup(
'maya', 'maya',
'ujson', 'ujson',
'PrettyTable', 'PrettyTable',
'progressbar2',
], ],
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'hive=hive.cli:cli', 'hive=hive.cli:cli',
] ]
}) })
\ No newline at end of file
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