Skip to content
Snippets Groups Projects
Commit 05a2c5b1 authored by roadscape's avatar roadscape
Browse files

accounts - remove bandwidth, fix bug #151 #152

parent 355cbe0b
No related branches found
No related tags found
No related merge requests found
...@@ -205,6 +205,16 @@ class DbState: ...@@ -205,6 +205,16 @@ class DbState:
cls.db().query(sql) cls.db().query(sql)
cls._set_ver(5) cls._set_ver(5)
if cls._ver == 5:
# recover acct names lost to issue #151
from hive.steem.client import SteemClient
from hive.indexer.accounts import Accounts
names = SteemClient().get_all_account_names()
Accounts.load_ids()
Accounts.register(names, '1970-01-01T00:00:00')
Accounts.clear_ids()
cls._set_ver(6)
assert cls._ver == DB_VERSION, "migration missing or invalid DB_VERSION" assert cls._ver == DB_VERSION, "migration missing or invalid DB_VERSION"
# Example migration: # Example migration:
#if cls._ver == 1: #if cls._ver == 1:
......
...@@ -10,7 +10,7 @@ from sqlalchemy.types import BOOLEAN ...@@ -10,7 +10,7 @@ from sqlalchemy.types import BOOLEAN
#pylint: disable=line-too-long, too-many-lines #pylint: disable=line-too-long, too-many-lines
DB_VERSION = 5 DB_VERSION = 6
def build_metadata(): def build_metadata():
"""Build schema def with SqlAlchemy""" """Build schema def with SqlAlchemy"""
...@@ -53,7 +53,7 @@ def build_metadata(): ...@@ -53,7 +53,7 @@ def build_metadata():
sa.Column('post_count', sa.Integer, nullable=False, server_default='0'), sa.Column('post_count', sa.Integer, nullable=False, server_default='0'),
sa.Column('proxy_weight', sa.Float(precision=6), nullable=False, server_default='0'), sa.Column('proxy_weight', sa.Float(precision=6), nullable=False, server_default='0'),
sa.Column('vote_weight', sa.Float(precision=6), nullable=False, server_default='0'), sa.Column('vote_weight', sa.Float(precision=6), nullable=False, server_default='0'),
sa.Column('kb_used', sa.Integer, nullable=False, server_default='0'), sa.Column('kb_used', sa.Integer, nullable=False, server_default='0'), # deprecated
sa.Column('rank', sa.Integer, nullable=False, server_default='0'), sa.Column('rank', sa.Integer, nullable=False, server_default='0'),
sa.Column('active_at', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'), sa.Column('active_at', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
......
...@@ -35,6 +35,11 @@ class Accounts: ...@@ -35,6 +35,11 @@ class Accounts:
assert not cls._ids, "id map already loaded" assert not cls._ids, "id map already loaded"
cls._ids = dict(DB.query_all("SELECT name, id FROM hive_accounts")) cls._ids = dict(DB.query_all("SELECT name, id FROM hive_accounts"))
@classmethod
def clear_ids(cls):
"""Wipe id map. Only used for db migration #5."""
cls._ids = None
@classmethod @classmethod
def get_id(cls, name): def get_id(cls, name):
"""Get account id by name. Throw if not found.""" """Get account id by name. Throw if not found."""
...@@ -157,15 +162,19 @@ class Accounts: ...@@ -157,15 +162,19 @@ class Accounts:
profile = safe_profile_metadata(account) profile = safe_profile_metadata(account)
del account['json_metadata'] del account['json_metadata']
active_at = max(account['created'],
account['last_post'],
account['last_vote_time'])
values = { values = {
'name': account['name'], 'name': account['name'],
'created_at': account['created'],
'proxy': account['proxy'], 'proxy': account['proxy'],
'post_count': account['post_count'], 'post_count': account['post_count'],
'reputation': rep_log10(account['reputation']), 'reputation': rep_log10(account['reputation']),
'proxy_weight': vests_amount(account['vesting_shares']), 'proxy_weight': vests_amount(account['vesting_shares']),
'vote_weight': vote_weight, 'vote_weight': vote_weight,
'kb_used': int(account['lifetime_bandwidth']) / 1e6 / 1024, 'active_at': active_at,
'active_at': account['last_bandwidth_update'],
'cached_at': cached_at, 'cached_at': cached_at,
'display_name': profile['name'], 'display_name': profile['name'],
......
...@@ -80,13 +80,12 @@ class Blocks: ...@@ -80,13 +80,12 @@ class Blocks:
account_names.add(op['new_account_name']) account_names.add(op['new_account_name'])
elif op_type == 'account_create_with_delegation_operation': elif op_type == 'account_create_with_delegation_operation':
account_names.add(op['new_account_name']) account_names.add(op['new_account_name'])
elif op_type == 'create_claimed_account': elif op_type == 'create_claimed_account_operation':
account_names.add(op['new_account_name']) account_names.add(op['new_account_name'])
# post ops # post ops
elif op_type == 'comment_operation': elif op_type == 'comment_operation':
comment_ops.append(op) comment_ops.append(op)
account_names.add(op['author']) # temp: HF20 missing account bug
elif op_type == 'delete_comment_operation': elif op_type == 'delete_comment_operation':
delete_ops.append(op) delete_ops.append(op)
elif op_type == 'vote_operation': elif op_type == 'vote_operation':
......
...@@ -29,6 +29,15 @@ class SteemClient: ...@@ -29,6 +29,15 @@ class SteemClient:
% (len(accounts), len(ret))) % (len(accounts), len(ret)))
return ret return ret
def get_all_account_names(self):
"""Fetch all account names."""
ret = []
names = self.__exec('lookup_accounts', ['', 1000])
while names:
ret.extend(names)
names = self.__exec('lookup_accounts', [names[-1], 1000])[1:]
return ret
def get_content_batch(self, tuples): def get_content_batch(self, tuples):
"""Fetch multiple comment objects.""" """Fetch multiple comment objects."""
posts = self.__exec_batch('get_content', tuples) posts = self.__exec_batch('get_content', tuples)
......
...@@ -82,6 +82,7 @@ class HttpClient(object): ...@@ -82,6 +82,7 @@ class HttpClient(object):
"""Simple Steem JSON-HTTP-RPC API""" """Simple Steem JSON-HTTP-RPC API"""
METHOD_API = dict( METHOD_API = dict(
lookup_accounts='condenser_api',
get_block='block_api', get_block='block_api',
get_content='condenser_api', get_content='condenser_api',
get_accounts='condenser_api', get_accounts='condenser_api',
......
...@@ -89,6 +89,7 @@ class SteemStats(StatsAbstract): ...@@ -89,6 +89,7 @@ class SteemStats(StatsAbstract):
'get_content': 4, 'get_content': 4,
'get_order_book': 20, 'get_order_book': 20,
'get_feed_history': 20, 'get_feed_history': 20,
'lookup_accounts': 1000,
} }
def __init__(self): def __init__(self):
......
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