Skip to content
Snippets Groups Projects
Commit 5bd75a57 authored by Mariusz Trela's avatar Mariusz Trela
Browse files

Merge branch 'mt-get-profile' of https://gitlab.syncad.com/hive/hivemind into mt-get-profile

parents f96ebc94 50be8ccc
No related branches found
No related tags found
5 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!138Small typos fixed,!135Enable postgres monitoring on CI server,!110Teh call `get_profile` works
......@@ -128,7 +128,6 @@ class DbState:
#'hive_posts_cache_ix32', # API: community created
#'hive_posts_cache_ix33', # API: community payout
#'hive_posts_cache_ix34', # API: community muted
'hive_accounts_ix1', # (cached_at, name)
'hive_accounts_ix5' # (cached_at, name)
]
......@@ -297,7 +296,6 @@ class DbState:
cls._set_ver(3)
if cls._ver == 3:
cls.db().query("CREATE INDEX hive_accounts_ix3 ON hive_accounts (vote_weight, name varchar_pattern_ops)")
cls._set_ver(4)
if cls._ver == 4:
......
......@@ -49,19 +49,15 @@ def build_metadata():
sa.Column('following', sa.Integer, nullable=False, server_default='0'),
sa.Column('proxy', VARCHAR(16), nullable=False, server_default=''),
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('vote_weight', sa.Float(precision=6), 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('lastread_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'),
sa.Column('cached_at', sa.DateTime, nullable=False, server_default='1970-01-01 00:00:00'),
sa.Column('raw_json', sa.Text),
sa.UniqueConstraint('name', name='hive_accounts_ux1'),
sa.Index('hive_accounts_ix1', 'vote_weight'), # core: quick ranks
sa.Index('hive_accounts_ix5', 'cached_at'), # core/listen sweep
)
......
......@@ -140,13 +140,6 @@ class Accounts:
cls._cache_accounts(accounts, steem, trx=trx)
return count
@classmethod
def fetch_ranks(cls):
"""Rebuild account ranks and store in memory for next update."""
sql = "SELECT id FROM hive_accounts ORDER BY vote_weight DESC"
for rank, _id in enumerate(DB.query_col(sql)):
cls._ranks[_id] = rank + 1
@classmethod
def _cache_accounts(cls, accounts, steem, trx=True):
"""Fetch all `accounts` and write to db."""
......@@ -170,9 +163,10 @@ class Accounts:
"""Prepare a SQL query from a steemd account."""
vests = vests_amount(account['vesting_shares'])
vote_weight = (vests
+ vests_amount(account['received_vesting_shares'])
- vests_amount(account['delegated_vesting_shares']))
#Not used. The member `vote_weight` from `hive_accounts` is removed.
# vote_weight = (vests
# + vests_amount(account['received_vesting_shares'])
# - vests_amount(account['delegated_vesting_shares']))
proxy_weight = 0 if account['proxy'] else float(vests)
for satoshis in account['proxied_vsf_votes']:
......@@ -190,21 +184,12 @@ class Accounts:
del account['json_metadata']
del account['posting_json_metadata']
active_at = max(account['created'],
account['last_account_update'],
account['last_post'],
account['last_root_post'],
account['last_vote_time'])
values = {
'name': account['name'],
'created_at': account['created'],
'proxy': account['proxy'],
'post_count': account['post_count'],
'reputation': rep_log10(account['reputation']),
'proxy_weight': proxy_weight,
'vote_weight': vote_weight,
'active_at': active_at,
'cached_at': cached_at,
'display_name': profile['name'],
......
......@@ -224,7 +224,6 @@ class Sync:
# prefetch id->name and id->rank memory maps
Accounts.load_ids()
Accounts.fetch_ranks()
# load irredeemables
mutes = Mutes(
......@@ -388,7 +387,6 @@ class Sync:
if num % 1200 == 0: #1hr
log.warning("head block %d @ %s", num, block['timestamp'])
log.info("[LIVE] hourly stats")
Accounts.fetch_ranks()
#Community.recalc_pending_payouts()
if num % 200 == 0: #10min
Community.recalc_pending_payouts()
......
......@@ -16,10 +16,8 @@ log = logging.getLogger(__name__)
async def load_profiles(db, names):
"""`get_accounts`-style lookup for `get_state` compat layer."""
sql = """SELECT id, name, display_name, about, reputation, vote_weight,
created_at, post_count, profile_image, location, website,
cover_image, rank, following, followers, active_at
FROM hive_accounts WHERE name IN :names"""
sql = """SELECT * FROM hive_accounts_info_view
WHERE name IN :names"""
rows = await db.query_all(sql, names=tuple(names))
return [_condenser_profile_object(row) for row in rows]
......@@ -197,6 +195,8 @@ def _condenser_profile_object(row):
blacklists = Mutes.lists(row['name'], row['reputation'])
#Important. The member `sp` in `stats` is removed, because currently the hivemind doesn't hold any balances.
# The member `vote_weight` from `hive_accounts` is removed as well.
return {
'id': row['id'],
'name': row['name'],
......@@ -206,16 +206,15 @@ def _condenser_profile_object(row):
'reputation': row['reputation'],
'blacklists': blacklists,
'stats': {
'sp': int(row['vote_weight'] * 0.0005037),
'rank': row['rank'],
'following': row['following'],
'followers': row['followers'],
},
'metadata': {
'profile': {'name': row['display_name'],
'about': row['about'],
'website': row['website'],
'location': row['location'],
'profile': {'name': row['display_name'] if row['display_name'] else "",
'about': row['about'] if row['about'] else "",
'website': row['website'] if row['website'] else "",
'location': row['location'] if row['location'] else "",
'cover_image': row['cover_image'],
'profile_image': row['profile_image'],
}}}
......
......@@ -460,7 +460,6 @@ async def get_accounts(db, accounts: list):
account_data['proxy'] = row.proxy
account_data['post_count'] = row.post_count
account_data['proxy_weight'] = row.proxy_weight
account_data['vote_weight'] = row.vote_weight
account_data['rank'] = row.rank
account_data['lastread_at'] = row.lastread_at.isoformat()
......
......@@ -14,10 +14,8 @@ log = logging.getLogger(__name__)
async def load_accounts(db, names):
"""`get_accounts`-style lookup for `get_state` compat layer."""
sql = """SELECT id, name, display_name, about, reputation, vote_weight,
created_at, post_count, profile_image, location, website,
cover_image
FROM hive_accounts WHERE name IN :names"""
sql = """SELECT * FROM hive_accounts_info_view
WHERE name IN :names"""
rows = await db.query_all(sql, names=tuple(names))
return [_condenser_account_object(row) for row in rows]
......@@ -156,12 +154,13 @@ async def _query_author_rep_map(db, posts):
def _condenser_account_object(row):
"""Convert an internal account record into legacy-steemd style."""
#The member `vote_weight` from `hive_accounts` is removed, so currently the member `net_vesting_shares` is equals to zero.
return {
'name': row['name'],
'created': str(row['created_at']),
'post_count': row['post_count'],
'reputation': rep_to_raw(row['reputation']),
'net_vesting_shares': row['vote_weight'],
'net_vesting_shares': 0,
'transfer_history': [],
'json_metadata': json.dumps({
'profile': {'name': row['display_name'],
......
......@@ -10,7 +10,7 @@ async def accounts_by_name(db, names, observer=None, lite=True):
"""Find and return accounts by `name`."""
sql = """SELECT id, name, display_name, about, created_at,
vote_weight, rank, followers, following %s
rank, followers, following %s
FROM hive_accounts WHERE name IN :names"""
fields = '' if lite else ', location, website, profile_image, cover_image'
rows = await db.query_all(sql % fields, names=tuple(names))
......@@ -21,7 +21,6 @@ async def accounts_by_name(db, names, observer=None, lite=True):
'id': row['id'],
'name': row['name'],
'created': str(row['created_at']).split(' ')[0],
'sp': int(estimated_sp(row['vote_weight'])),
'rank': row['rank'],
'followers': row['followers'],
'following': row['following'],
......
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