Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
c9499d1a
Commit
c9499d1a
authored
7 years ago
by
Tim
Browse files
Options
Downloads
Patches
Plain Diff
add progress bar, batch steemd blocks
parent
d677bbed
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hive/indexer/core.py
+13
-3
13 additions, 3 deletions
hive/indexer/core.py
setup.py
+2
-1
2 additions, 1 deletion
setup.py
with
15 additions
and
4 deletions
hive/indexer/core.py
+
13
−
3
View file @
c9499d1a
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
%
1000
00
==
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
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
2
−
1
View file @
c9499d1a
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment