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
d5dd602c
Commit
d5dd602c
authored
4 years ago
by
Mariusz Trela
Browse files
Options
Downloads
Patches
Plain Diff
Votes inserted by `vote_operation` and updated by `effective_comment_vote_operation` operation
parent
b3c788a0
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
,
!61
Issue #47 - test database_api get_payout_stats fail
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/indexer/blocks.py
+2
-1
2 additions, 1 deletion
hive/indexer/blocks.py
hive/indexer/posts.py
+6
-5
6 additions, 5 deletions
hive/indexer/posts.py
hive/indexer/votes.py
+91
-17
91 additions, 17 deletions
hive/indexer/votes.py
with
99 additions
and
23 deletions
hive/indexer/blocks.py
+
2
−
1
View file @
d5dd602c
...
...
@@ -229,6 +229,7 @@ class Blocks:
if
not
is_initial_sync
:
Accounts
.
dirty
(
op
[
'
author
'
])
# lite - rep
Accounts
.
dirty
(
op
[
'
voter
'
])
# lite - stats
Votes
.
vote_op
(
op
)
# misc ops
elif
op_type
==
'
transfer_operation
'
:
...
...
@@ -254,7 +255,7 @@ class Blocks:
(
vote_ops
,
comment_payout_ops
)
=
Blocks
.
prepare_vops
(
vops
,
cls
.
_head_block_date
)
for
k
,
v
in
vote_ops
.
items
():
Votes
.
vote_op
(
v
,
cls
.
_head_block_date
)
Votes
.
effective_comment_
vote_op
(
v
,
cls
.
_head_block_date
)
op_type
=
'
effective_comment_vote_operation
'
if
op_type
in
cls
.
ops_stats
:
cls
.
ops_stats
[
op_type
]
+=
1
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/posts.py
+
6
−
5
View file @
d5dd602c
...
...
@@ -287,13 +287,14 @@ class Posts:
pending_payout
=
0
#Calculations of all dates
if
(
total_payout_value
is
not
None
):
payout_at
=
date
last_payout
=
date
if
(
is_paidout
is
not
None
):
payout_at
=
date
cashout_time
=
date
last_payout
=
date
cashout_time
=
"
1969-12-31T23:59:59
"
else
:
if
(
total_payout_value
is
not
None
):
payout_at
=
date
#Here should be `cashout_time`
last_payout
=
date
values
.
append
(
"
(
'
{}
'
,
'
{}
'
, {}, {}, {}, {}, {}, {}, {}, {}, {},
'
{}
'
::timestamp, {}, {}, {})
"
.
format
(
author
,
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/votes.py
+
91
−
17
View file @
d5dd602c
...
...
@@ -10,6 +10,7 @@ DB = Db.instance()
class
Votes
:
"""
Class for managing posts votes
"""
_votes_data
=
{}
_effective_votes_data
=
{}
@classmethod
def
get_vote_count
(
cls
,
author
,
permlink
):
...
...
@@ -64,34 +65,51 @@ class Votes:
cls
.
_votes_data
[
key
]
=
dict
(
voter
=
voter
,
author
=
author
,
permlink
=
permlink
,
vote_percent
=
vop
[
'
vote_percent
'
],
weight
=
vop
[
'
weight
'
],
rshares
=
vop
[
'
rshares
'
],
last_update
=
date
)
weight
=
vop
[
'
weight
'
])
@classmethod
def
flush
(
cls
):
def
effective_comment_vote_op
(
cls
,
vop
,
date
):
"""
Process effective_comment_vote_operation
"""
voter
=
vop
[
'
voter
'
]
author
=
vop
[
'
author
'
]
permlink
=
vop
[
'
permlink
'
]
if
(
cls
.
inside_flush
):
log
.
info
(
"
Adding new effective comment vote into
'
_effective_votes_data
'
dict
"
)
raise
"
Fatal error
"
key
=
voter
+
"
/
"
+
author
+
"
/
"
+
permlink
cls
.
_effective_votes_data
[
key
]
=
dict
(
voter
=
voter
,
author
=
author
,
permlink
=
permlink
,
vote_percent
=
vop
[
'
vote_percent
'
],
weight
=
vop
[
'
weight
'
],
rshares
=
vop
[
'
rshares
'
],
last_update
=
date
)
@classmethod
def
flush_votes
(
cls
):
"""
Flush vote data from cache to database
"""
cls
.
inside_flush
=
True
if
cls
.
_votes_data
:
sql
=
"""
INSERT INTO hive_votes
(post_id, voter_id, author_id, permlink_id, weight
, rshares, vote_percent, last_update
)
select data_source.post_id, data_source.voter_id, data_source.author_id, data_source.permlink_id, data_source.weight
, data_source.rshares, data_source.vote_percent, data_source.last_update
from
(post_id, voter_id, author_id, permlink_id, weight)
select data_source.post_id, data_source.voter_id, data_source.author_id, data_source.permlink_id, data_source.weight
from
(
SELECT hp.id as post_id, ha_v.id as voter_id, ha_a.id as author_id, hpd_p.id as permlink_id, t.weight
, t.rshares, t.vote_percent, t.last_update
SELECT hp.id as post_id, ha_v.id as voter_id, ha_a.id as author_id, hpd_p.id as permlink_id, t.weight
from
(
VALUES
-- voter, author, permlink, weight
, rshares, vote_percent, last_update
-- voter, author, permlink, weight
{}
) AS T(voter, author, permlink, weight
, rshares, vote_percent, last_update
)
) AS T(voter, author, permlink, weight)
INNER JOIN hive_accounts ha_v ON ha_v.name = t.voter
INNER JOIN hive_accounts ha_a ON ha_a.name = t.author
INNER JOIN hive_permlink_data hpd_p ON hpd_p.permlink = t.permlink
INNER JOIN hive_posts hp ON hp.author_id = ha_a.id AND hp.permlink_id = hpd_p.id
) as data_source(post_id, voter_id, author_id, permlink_id, weight
, rshares, vote_percent, last_update
)
INNER JOIN hive_posts hp ON hp.author_id = ha_a.id AND hp.permlink_id = hpd_p.id
) as data_source(post_id, voter_id, author_id, permlink_id, weight)
ON CONFLICT ON CONSTRAINT hive_votes_ux1 DO
UPDATE
SET
...
...
@@ -107,8 +125,8 @@ class Votes:
values_limit
=
1000
for
_
,
vd
in
cls
.
_votes_data
.
items
():
values
.
append
(
"
(
'
{}
'
,
'
{}
'
,
'
{}
'
, {}
, {}, {},
'
{}
'
::timestamp
)
"
.
format
(
vd
[
'
voter
'
],
vd
[
'
author
'
],
vd
[
'
permlink
'
],
vd
[
'
weight
'
]
,
vd
[
'
rshares
'
],
vd
[
'
vote_percent
'
],
vd
[
'
last_update
'
]
))
values
.
append
(
"
(
'
{}
'
,
'
{}
'
,
'
{}
'
, {})
"
.
format
(
vd
[
'
voter
'
],
vd
[
'
author
'
],
vd
[
'
permlink
'
],
vd
[
'
weight
'
]))
if
len
(
values
)
>=
values_limit
:
values_str
=
'
,
'
.
join
(
values
)
...
...
@@ -123,4 +141,60 @@ class Votes:
values
.
clear
()
cls
.
_votes_data
.
clear
()
cls
.
inside_flush
=
False
@classmethod
def
flush_effective_votes
(
cls
):
"""
Flush vote data from cache to database
"""
if
cls
.
_effective_votes_data
:
sql
=
"""
UPDATE hive_votes AS hv SET
weight = data_source.weight,
rshares = data_source.rshares,
vote_percent = data_source.vote_percent,
last_update = data_source.last_update,
num_changes = hv.num_changes + 1
FROM
(
SELECT ha_v.id as voter_id, ha_a.id as author_id, hpd_p.id as permlink_id, t.weight, t.rshares, t.vote_percent, t.last_update
FROM
(
VALUES
-- voter, author, permlink, weight, rshares, vote_percent, last_update
{}
) AS T(voter, author, permlink, weight, rshares, vote_percent, last_update)
INNER JOIN hive_accounts ha_v ON ha_v.name = t.voter
INNER JOIN hive_accounts ha_a ON ha_a.name = t.author
INNER JOIN hive_permlink_data hpd_p ON hpd_p.permlink = t.permlink
) as data_source(voter_id, author_id, permlink_id, weight, rshares, vote_percent, last_update)
WHERE hv.voter_id = data_source.voter_id and hv.author_id = data_source.author_id and hv.permlink_id = data_source.permlink_id;
"""
values
=
[]
values_limit
=
1000
for
_
,
vd
in
cls
.
_effective_votes_data
.
items
():
values
.
append
(
"
(
'
{}
'
,
'
{}
'
,
'
{}
'
, {}, {}, {},
'
{}
'
::timestamp)
"
.
format
(
vd
[
'
voter
'
],
vd
[
'
author
'
],
vd
[
'
permlink
'
],
vd
[
'
weight
'
],
vd
[
'
rshares
'
],
vd
[
'
vote_percent
'
],
vd
[
'
last_update
'
]))
if
len
(
values
)
>=
values_limit
:
values_str
=
'
,
'
.
join
(
values
)
actual_query
=
sql
.
format
(
values_str
)
DB
.
query
(
actual_query
)
values
.
clear
()
if
len
(
values
)
>
0
:
values_str
=
'
,
'
.
join
(
values
)
actual_query
=
sql
.
format
(
values_str
)
DB
.
query
(
actual_query
)
values
.
clear
()
cls
.
_effective_votes_data
.
clear
()
@classmethod
def
flush
(
cls
):
cls
.
inside_flush
=
True
cls
.
flush_votes
()
cls
.
flush_effective_votes
()
cls
.
inside_flush
=
False
\ 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