Skip to content
Snippets Groups Projects
Commit 68de498e authored by Andrzej Lisak's avatar Andrzej Lisak
Browse files

[ABW]: fixed calculation of changes in votes - they were previously be counted...

[ABW]: fixed calculation of changes in votes - they were previously be counted when they happened to fall into the same package of blocks
parent 18a33652
No related branches found
No related tags found
3 merge requests!456Release candidate v1 24,!261Mi livesync hot and trends2,!242Fix in calculation of num_changes for votes
......@@ -34,6 +34,7 @@ class Votes(DbAdapterHolder):
if key in cls._votes_data:
cls._votes_data[key]["vote_percent"] = weight
cls._votes_data[key]["last_update"] = date
# only effective vote edits increase num_changes counter
else:
cls._votes_data[key] = dict(voter=voter,
author=author,
......@@ -43,6 +44,7 @@ class Votes(DbAdapterHolder):
rshares=0,
last_update=date,
is_effective=False,
num_changes=0,
block_num=block_num)
@classmethod
......@@ -55,17 +57,19 @@ class Votes(DbAdapterHolder):
cls._votes_data[key]["weight"] = vop["weight"]
cls._votes_data[key]["rshares"] = vop["rshares"]
cls._votes_data[key]["is_effective"] = True
cls._votes_data[key]["block_num"] = vop['block_num']
cls._votes_data[key]["num_changes"] += 1
cls._votes_data[key]["block_num"] = vop["block_num"]
else:
cls._votes_data[key] = dict(voter=vop['voter'],
author=vop['author'],
permlink=escape_characters(vop['permlink']),
cls._votes_data[key] = dict(voter=vop["voter"],
author=vop["author"],
permlink=escape_characters(vop["permlink"]),
vote_percent=0,
weight=vop["weight"],
rshares=vop["rshares"],
last_update='1970-01-01 00:00:00',
last_update="1970-01-01 00:00:00",
is_effective=True,
block_num=vop['block_num'])
num_changes=0,
block_num=vop["block_num"])
@classmethod
def flush(cls):
""" Flush vote data from cache to database """
......@@ -77,16 +81,16 @@ class Votes(DbAdapterHolder):
sql = """
INSERT INTO hive_votes
(post_id, voter_id, author_id, permlink_id, weight, rshares, vote_percent, last_update, block_num, is_effective)
(post_id, voter_id, author_id, permlink_id, weight, rshares, vote_percent, last_update, num_changes, block_num, is_effective)
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, t.block_num, t.is_effective
t.weight, t.rshares, t.vote_percent, t.last_update, t.num_changes, t.block_num, t.is_effective
FROM
(
VALUES
-- order_id, voter, author, permlink, weight, rshares, vote_percent, last_update, block_num, is_effective
-- order_id, voter, author, permlink, weight, rshares, vote_percent, last_update, num_changes, block_num, is_effective
{}
) AS T(order_id, voter, author, permlink, weight, rshares, vote_percent, last_update, block_num, is_effective)
) AS T(order_id, voter, author, permlink, weight, rshares, vote_percent, last_update, num_changes, block_num, is_effective)
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
......@@ -100,7 +104,7 @@ class Votes(DbAdapterHolder):
rshares = CASE EXCLUDED.is_effective WHEN true THEN EXCLUDED.rshares ELSE hive_votes.rshares END,
vote_percent = EXCLUDED.vote_percent,
last_update = EXCLUDED.last_update,
num_changes = hive_votes.num_changes + 1
num_changes = hive_votes.num_changes + EXCLUDED.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 clause above seems superfluous (and works all the same without it, at least up to 5mln)
......@@ -109,10 +113,10 @@ class Votes(DbAdapterHolder):
values_limit = 1000
for _, vd in cls._votes_data.items():
values.append("({}, '{}', '{}', {}, {}, {}, {}, '{}'::timestamp, {}, {})".format(
values.append("({}, '{}', '{}', {}, {}, {}, {}, '{}'::timestamp, {}, {}, {})".format(
len(values), # for ordering
vd['voter'], vd['author'], vd['permlink'], vd['weight'], vd['rshares'],
vd['vote_percent'], vd['last_update'], vd['block_num'], vd['is_effective']))
vd['vote_percent'], vd['last_update'], vd['num_changes'], vd['block_num'], vd['is_effective']))
if len(values) >= values_limit:
values_str = ','.join(values)
......
Subproject commit 3cd0ed4857180f0fa29e9eab9337acdc129aac5f
Subproject commit aa45a4b82acf3004cc12a9016a5ad24454f2a92e
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