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
c6c1bcaf
Commit
c6c1bcaf
authored
4 years ago
by
Bartek Wrona
Browse files
Options
Downloads
Plain Diff
Merge branch 'dk-improvements-001' into 'develop'
Improvements See merge request
!58
parents
7fe697f5
e6864f86
No related branches found
No related tags found
4 merge requests
!456
Release candidate v1 24
,
!230
Setup monitoring with pghero
,
!135
Enable postgres monitoring on CI server
,
!58
Improvements
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/indexer/accounts.py
+9
-10
9 additions, 10 deletions
hive/indexer/accounts.py
hive/indexer/blocks.py
+17
-23
17 additions, 23 deletions
hive/indexer/blocks.py
hive/indexer/community.py
+20
-21
20 additions, 21 deletions
hive/indexer/community.py
with
46 additions
and
54 deletions
hive/indexer/accounts.py
+
9
−
10
View file @
c6c1bcaf
...
@@ -70,7 +70,7 @@ class Accounts:
...
@@ -70,7 +70,7 @@ class Accounts:
return
False
return
False
@classmethod
@classmethod
def
register
(
cls
,
name
s
,
block_date
):
def
register
(
cls
,
name
,
block_date
):
"""
Block processing: register
"
candidate
"
names.
"""
Block processing: register
"
candidate
"
names.
There are four ops which can result in account creation:
There are four ops which can result in account creation:
...
@@ -79,24 +79,23 @@ class Accounts:
...
@@ -79,24 +79,23 @@ class Accounts:
the account they name does not already exist!
the account they name does not already exist!
"""
"""
if
name
is
None
:
return
# filter out names which already registered
# filter out names which already registered
new_names
=
list
(
filter
(
lambda
n
:
not
cls
.
exists
(
n
),
set
(
names
)))
if
cls
.
exists
(
name
):
if
not
new_names
:
return
return
for
name
in
new_names
:
DB
.
query
(
"
INSERT INTO hive_accounts (name, created_at) VALUES (:name, :date)
"
,
name
=
name
,
date
=
block_date
)
DB
.
query
(
"
INSERT INTO hive_accounts (name, created_at)
"
"
VALUES (:name, :date)
"
,
name
=
name
,
date
=
block_date
)
# pull newly-inserted ids and merge into our map
# pull newly-inserted ids and merge into our map
sql
=
"
SELECT name, id FROM hive_accounts WHERE name IN :names
"
sql
=
"
SELECT id FROM hive_accounts WHERE name = :name
"
for
name
,
_id
in
DB
.
query_all
(
sql
,
names
=
tuple
(
new_names
)):
cls
.
_ids
[
name
]
=
DB
.
query_one
(
sql
,
name
=
name
)
cls
.
_ids
[
name
]
=
_id
# post-insert: pass to communities to check for new registrations
# post-insert: pass to communities to check for new registrations
from
hive.indexer.community
import
Community
,
START_DATE
from
hive.indexer.community
import
Community
,
START_DATE
if
block_date
>
START_DATE
:
if
block_date
>
START_DATE
:
Community
.
register
(
new_
name
s
,
block_date
)
Community
.
register
(
name
,
block_date
)
# account cache methods
# account cache methods
# ---------------------
# ---------------------
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/blocks.py
+
17
−
23
View file @
c6c1bcaf
...
@@ -64,6 +64,7 @@ class Blocks:
...
@@ -64,6 +64,7 @@ class Blocks:
PostDataCache
.
flush
()
PostDataCache
.
flush
()
Tags
.
flush
()
Tags
.
flush
()
Votes
.
flush
()
Votes
.
flush
()
cls
.
_flush_blocks
()
time_end
=
perf_counter
()
time_end
=
perf_counter
()
log
.
info
(
"
[PROCESS BLOCK] %fs
"
,
time_end
-
time_start
)
log
.
info
(
"
[PROCESS BLOCK] %fs
"
,
time_end
-
time_start
)
return
ret
return
ret
...
@@ -140,43 +141,30 @@ class Blocks:
...
@@ -140,43 +141,30 @@ class Blocks:
# head block date shall point to last imported block (not yet current one) to conform hived behavior.
# head block date shall point to last imported block (not yet current one) to conform hived behavior.
# that's why operations processed by node are included in the block being currently produced, so its processing time is equal to last produced block.
# that's why operations processed by node are included in the block being currently produced, so its processing time is equal to last produced block.
if
(
cls
.
_head_block_date
is
None
)
:
if
cls
.
_head_block_date
is
None
:
cls
.
_head_block_date
=
block_date
cls
.
_head_block_date
=
block_date
# [DK] we will make two scans, first scan will register all accounts
json_ops
=
[]
account_names
=
set
()
update_comment_pending_payouts
=
[]
for
tx_idx
,
tx
in
enumerate
(
block
[
'
transactions
'
]):
for
tx_idx
,
tx
in
enumerate
(
block
[
'
transactions
'
]):
for
operation
in
tx
[
'
operations
'
]:
for
operation
in
tx
[
'
operations
'
]:
op_type
=
operation
[
'
type
'
]
op_type
=
operation
[
'
type
'
]
op
=
operation
[
'
value
'
]
op
=
operation
[
'
value
'
]
account_name
=
None
# account ops
# account ops
if
op_type
==
'
pow_operation
'
:
if
op_type
==
'
pow_operation
'
:
account_name
s
.
add
(
op
[
'
worker_account
'
]
)
account_name
=
op
[
'
worker_account
'
]
elif
op_type
==
'
pow2_operation
'
:
elif
op_type
==
'
pow2_operation
'
:
account_name
s
.
add
(
op
[
'
work
'
][
'
value
'
][
'
input
'
][
'
worker_account
'
]
)
account_name
=
op
[
'
work
'
][
'
value
'
][
'
input
'
][
'
worker_account
'
]
elif
op_type
==
'
account_create_operation
'
:
elif
op_type
==
'
account_create_operation
'
:
account_name
s
.
add
(
op
[
'
new_account_name
'
]
)
account_name
=
op
[
'
new_account_name
'
]
elif
op_type
==
'
account_create_with_delegation_operation
'
:
elif
op_type
==
'
account_create_with_delegation_operation
'
:
account_name
s
.
add
(
op
[
'
new_account_name
'
]
)
account_name
=
op
[
'
new_account_name
'
]
elif
op_type
==
'
create_claimed_account_operation
'
:
elif
op_type
==
'
create_claimed_account_operation
'
:
account_names
.
add
(
op
[
'
new_account_name
'
])
account_name
=
op
[
'
new_account_name
'
]
Accounts
.
register
(
account_names
,
cls
.
_head_block_date
)
# register any new names
# second scan will process all other ops
json_ops
=
[]
update_comment_pending_payouts
=
[]
for
tx_idx
,
tx
in
enumerate
(
block
[
'
transactions
'
]):
for
operation
in
tx
[
'
operations
'
]:
op_type
=
operation
[
'
type
'
]
op
=
operation
[
'
value
'
]
if
(
op_type
!=
'
custom_json_operation
'
):
Accounts
.
register
(
account_name
,
cls
.
_head_block_date
)
if
op_type
in
cls
.
ops_stats
:
cls
.
ops_stats
[
op_type
]
+=
1
else
:
cls
.
ops_stats
[
op_type
]
=
1
# account metadata updates
# account metadata updates
if
op_type
==
'
account_update_operation
'
:
if
op_type
==
'
account_update_operation
'
:
...
@@ -208,6 +196,12 @@ class Blocks:
...
@@ -208,6 +196,12 @@ class Blocks:
elif
op_type
==
'
custom_json_operation
'
:
elif
op_type
==
'
custom_json_operation
'
:
json_ops
.
append
(
op
)
json_ops
.
append
(
op
)
if
op_type
!=
'
custom_json_operation
'
:
if
op_type
in
cls
.
ops_stats
:
cls
.
ops_stats
[
op_type
]
+=
1
else
:
cls
.
ops_stats
[
op_type
]
=
1
# follow/reblog/community ops
# follow/reblog/community ops
if
json_ops
:
if
json_ops
:
custom_ops_stats
=
CustomOp
.
process_ops
(
json_ops
,
num
,
cls
.
_head_block_date
)
custom_ops_stats
=
CustomOp
.
process_ops
(
json_ops
,
num
,
cls
.
_head_block_date
)
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/community.py
+
20
−
21
View file @
c6c1bcaf
...
@@ -104,33 +104,32 @@ class Community:
...
@@ -104,33 +104,32 @@ class Community:
_names
=
{}
_names
=
{}
@classmethod
@classmethod
def
register
(
cls
,
name
s
,
block_date
):
def
register
(
cls
,
name
,
block_date
):
"""
Block processing: hooks into new account registration.
"""
Block processing: hooks into new account registration.
`Accounts` calls this method with any newly registered names.
`Accounts` calls this method with any newly registered names.
This method checks for any valid community names and inserts them.
This method checks for any valid community names and inserts them.
"""
"""
for
name
in
names
:
#if not re.match(r'^hive-[123]\d{4,6}$', name):
#if not re.match(r'^hive-[123]\d{4,6}$', name):
if
not
re
.
match
(
r
'
^hive-[1]\d{4,6}$
'
,
name
):
if
not
re
.
match
(
r
'
^hive-[1]\d{4,6}$
'
,
name
):
return
continue
type_id
=
int
(
name
[
5
])
type_id
=
int
(
name
[
5
])
_id
=
Accounts
.
get_id
(
name
)
_id
=
Accounts
.
get_id
(
name
)
# insert community
# insert community
sql
=
"""
INSERT INTO hive_communities (id, name, type_id, created_at)
sql
=
"""
INSERT INTO hive_communities (id, name, type_id, created_at)
VALUES (:id, :name, :type_id, :date)
"""
VALUES (:id, :name, :type_id, :date)
"""
DB
.
query
(
sql
,
id
=
_id
,
name
=
name
,
type_id
=
type_id
,
date
=
block_date
)
DB
.
query
(
sql
,
id
=
_id
,
name
=
name
,
type_id
=
type_id
,
date
=
block_date
)
# insert owner
# insert owner
sql
=
"""
INSERT INTO hive_roles (community_id, account_id, role_id, created_at)
sql
=
"""
INSERT INTO hive_roles (community_id, account_id, role_id, created_at)
VALUES (:community_id, :account_id, :role_id, :date)
"""
VALUES (:community_id, :account_id, :role_id, :date)
"""
DB
.
query
(
sql
,
community_id
=
_id
,
account_id
=
_id
,
DB
.
query
(
sql
,
community_id
=
_id
,
account_id
=
_id
,
role_id
=
Role
.
owner
.
value
,
date
=
block_date
)
role_id
=
Role
.
owner
.
value
,
date
=
block_date
)
Notify
(
'
new_community
'
,
src_id
=
None
,
dst_id
=
_id
,
Notify
(
'
new_community
'
,
src_id
=
None
,
dst_id
=
_id
,
when
=
block_date
,
community_id
=
_id
).
write
()
when
=
block_date
,
community_id
=
_id
).
write
()
@classmethod
@classmethod
def
validated_id
(
cls
,
name
):
def
validated_id
(
cls
,
name
):
...
...
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