This commit is contained in:
parent
d6bf3e1602
commit
ea16de3f1a
|
@ -64,8 +64,8 @@ async def get_author(_, _info, slug='', author_id=0):
|
||||||
if isinstance(author, Author):
|
if isinstance(author, Author):
|
||||||
author_id = author.id
|
author_id = author.id
|
||||||
logger.debug(f'found @{slug} with id {author_id}')
|
logger.debug(f'found @{slug} with id {author_id}')
|
||||||
if not author.stat:
|
if not author.stat or not author.stat['rating']:
|
||||||
[author] = get_with_stat(author_query)
|
[author] = get_with_stat(author_query, with_rating=True)
|
||||||
if author:
|
if author:
|
||||||
await set_author_cache(author.dict())
|
await set_author_cache(author.dict())
|
||||||
logger.debug('updated author stored in cache')
|
logger.debug('updated author stored in cache')
|
||||||
|
|
|
@ -162,13 +162,14 @@ def add_author_ratings(q):
|
||||||
return q.join(ratings_subquery, Author.id == ratings_subquery.c.author_id)
|
return q.join(ratings_subquery, Author.id == ratings_subquery.c.author_id)
|
||||||
|
|
||||||
|
|
||||||
def get_with_stat(q):
|
def get_with_stat(q, with_rating=False):
|
||||||
try:
|
try:
|
||||||
is_author = f'{q}'.lower().startswith('select author')
|
is_author = f'{q}'.lower().startswith('select author')
|
||||||
is_topic = f'{q}'.lower().startswith('select topic')
|
is_topic = f'{q}'.lower().startswith('select topic')
|
||||||
if is_author:
|
if is_author:
|
||||||
q = add_author_stat_columns(q)
|
q = add_author_stat_columns(q)
|
||||||
q = add_author_ratings(q) # TODO: move rating to cols down there
|
if with_rating:
|
||||||
|
q = add_author_ratings(q)
|
||||||
elif is_topic:
|
elif is_topic:
|
||||||
q = add_topic_stat_columns(q)
|
q = add_topic_stat_columns(q)
|
||||||
records = []
|
records = []
|
||||||
|
@ -184,8 +185,9 @@ def get_with_stat(q):
|
||||||
if is_author:
|
if is_author:
|
||||||
stat['comments'] = cols[4]
|
stat['comments'] = cols[4]
|
||||||
# entity.stat['topics'] = cols[5]
|
# entity.stat['topics'] = cols[5]
|
||||||
entity.stat['rating'] = cols[5] - cols[6]
|
if with_rating:
|
||||||
entity.stat['rating_shouts'] = cols[7] - cols[8]
|
entity.stat['rating'] = cols[5] - cols[6]
|
||||||
|
entity.stat['rating_shouts'] = cols[7] - cols[8]
|
||||||
entity.stat = stat
|
entity.stat = stat
|
||||||
records.append(entity)
|
records.append(entity)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user