Skip to content
Snippets Groups Projects
Commit d9dd51eb authored by Bartek Wrona's avatar Bartek Wrona
Browse files

Merge branch 'final_vote_fix' into 'develop'

Votes now properly retain weight/rshares of last effective_comment_vote_operation

See merge request !69
parents 03edafa1 77c8ee15
No related branches found
No related tags found
4 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!135Enable postgres monitoring on CI server,!69Votes now properly retain weight/rshares of last effective_comment_vote_operation
...@@ -238,7 +238,7 @@ class Blocks: ...@@ -238,7 +238,7 @@ class Blocks:
if vote_ops is not None: if vote_ops is not None:
for k, v in vote_ops.items(): for k, v in vote_ops.items():
Votes.effective_comment_vote_op(k, v, cls._head_block_date) Votes.effective_comment_vote_op(k, v)
if Posts.comment_payout_ops: if Posts.comment_payout_ops:
cls.ops_stats = Blocks.merge_ops_stats(cls.ops_stats, comment_payout_stats) cls.ops_stats = Blocks.merge_ops_stats(cls.ops_stats, comment_payout_stats)
......
...@@ -62,16 +62,21 @@ class Votes: ...@@ -62,16 +62,21 @@ class Votes:
key = voter + "/" + author + "/" + permlink key = voter + "/" + author + "/" + permlink
cls._votes_data[key] = dict(voter=voter, if key in cls._votes_data:
author=author, cls._votes_data[key]["vote_percent"]=weight
permlink=permlink, cls._votes_data[key]["last_update"]=date
vote_percent=weight, else:
weight=0, cls._votes_data[key] = dict(voter=voter,
rshares=0, author=author,
last_update=date) permlink=permlink,
vote_percent=weight,
weight=0,
rshares=0,
last_update=date,
is_effective=False)
@classmethod @classmethod
def effective_comment_vote_op(cls, key, vop, date): def effective_comment_vote_op(cls, key, vop):
""" Process effective_comment_vote_operation """ """ Process effective_comment_vote_operation """
if(cls.inside_flush): if(cls.inside_flush):
...@@ -80,9 +85,9 @@ class Votes: ...@@ -80,9 +85,9 @@ class Votes:
assert key in cls._votes_data assert key in cls._votes_data
cls._votes_data[key]["weight"] = vop["weight"] cls._votes_data[key]["weight"] = vop["weight"]
cls._votes_data[key]["rshares"] = vop["rshares"] cls._votes_data[key]["rshares"] = vop["rshares"]
cls._votes_data[key]["last_update"] = date cls._votes_data[key]["is_effective"] = True
@classmethod @classmethod
def flush(cls): def flush(cls):
...@@ -106,32 +111,49 @@ class Votes: ...@@ -106,32 +111,49 @@ class Votes:
ON CONFLICT ON CONSTRAINT hive_votes_ux1 DO ON CONFLICT ON CONSTRAINT hive_votes_ux1 DO
UPDATE UPDATE
SET SET
weight = (CASE (SELECT hp.is_paidout FROM hive_posts hp WHERE hp.id = EXCLUDED.post_id) WHEN true THEN hive_votes.weight ELSE EXCLUDED.weight END), weight = {}.weight,
rshares = (CASE (SELECT hp.is_paidout FROM hive_posts hp WHERE hp.id = EXCLUDED.post_id) WHEN true THEN hive_votes.rshares ELSE EXCLUDED.rshares END), rshares = {}.rshares,
vote_percent = EXCLUDED.vote_percent, vote_percent = EXCLUDED.vote_percent,
last_update = EXCLUDED.last_update, last_update = EXCLUDED.last_update,
num_changes = hive_votes.num_changes + 1 num_changes = hive_votes.num_changes + 1
WHERE hive_votes.voter_id = EXCLUDED.voter_id and hive_votes.author_id = EXCLUDED.author_id and hive_votes.permlink_id = EXCLUDED.permlink_id; WHERE hive_votes.voter_id = EXCLUDED.voter_id and hive_votes.author_id = EXCLUDED.author_id and hive_votes.permlink_id = EXCLUDED.permlink_id;
""" """
# WHERE clause above seems superfluous (and works all the same without it, at least up to 5mln)
values = [] values_skip = []
values_override = []
values_limit = 1000 values_limit = 1000
for _, vd in cls._votes_data.items(): for _, vd in cls._votes_data.items():
values = None
on_conflict_data_source = None
if vd['is_effective']:
values = values_override
on_conflict_data_source = 'EXCLUDED'
else:
values = values_skip
on_conflict_data_source = 'hive_votes'
values.append("('{}', '{}', '{}', {}, {}, {}, '{}'::timestamp)".format( values.append("('{}', '{}', '{}', {}, {}, {}, '{}'::timestamp)".format(
vd['voter'], vd['author'], vd['permlink'], vd['weight'], vd['rshares'], vd['vote_percent'], vd['last_update'])) vd['voter'], vd['author'], vd['permlink'], vd['weight'], vd['rshares'], vd['vote_percent'], vd['last_update']))
if len(values) >= values_limit: if len(values) >= values_limit:
values_str = ','.join(values) values_str = ','.join(values)
actual_query = sql.format(values_str) actual_query = sql.format(values_str,on_conflict_data_source,on_conflict_data_source)
DB.query(actual_query) DB.query(actual_query)
values.clear() values.clear()
if len(values) > 0: if len(values_skip) > 0:
values_str = ','.join(values) values_str = ','.join(values_skip)
actual_query = sql.format(values_str) actual_query = sql.format(values_str,'hive_votes','hive_votes')
DB.query(actual_query)
values_skip.clear()
if len(values_override) > 0:
values_str = ','.join(values_override)
actual_query = sql.format(values_str,'EXCLUDED','EXCLUDED')
DB.query(actual_query) DB.query(actual_query)
values.clear() values_override.clear()
cls._votes_data.clear() cls._votes_data.clear()
cls.inside_flush = False cls.inside_flush = False
Subproject commit 619f51ed6c85a016621b12fa1264c12c7d3d3156 Subproject commit 855f525d497119092d24bec91c1d29648fc04c2f
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