This commit is contained in:
parent
e529ecbe41
commit
4fe15d1440
|
@ -182,17 +182,17 @@ async def get_author_follows(_, _info, slug='', user=None, author_id=0):
|
||||||
rkey = f'author:{author_id}:follows-authors'
|
rkey = f'author:{author_id}:follows-authors'
|
||||||
logger.debug(f'getting {author_id} follows authors')
|
logger.debug(f'getting {author_id} follows authors')
|
||||||
cached = await redis.execute('GET', rkey)
|
cached = await redis.execute('GET', rkey)
|
||||||
|
authors = []
|
||||||
if not cached:
|
if not cached:
|
||||||
authors = author_follows_authors(author_id)
|
authors = author_follows_authors(author_id)
|
||||||
prepared = [author.dict() for author in authors]
|
prepared = [author.dict() for author in authors]
|
||||||
await redis.execute(
|
await redis.execute('SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder))
|
||||||
'SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder)
|
|
||||||
)
|
|
||||||
elif isinstance(cached, str):
|
elif isinstance(cached, str):
|
||||||
authors = json.loads(cached)
|
authors = json.loads(cached)
|
||||||
|
|
||||||
rkey = f'author:{author_id}:follows-topics'
|
rkey = f'author:{author_id}:follows-topics'
|
||||||
cached = await redis.execute('GET', rkey)
|
cached = await redis.execute('GET', rkey)
|
||||||
|
topics = []
|
||||||
if cached and isinstance(cached, str):
|
if cached and isinstance(cached, str):
|
||||||
topics = json.loads(cached)
|
topics = json.loads(cached)
|
||||||
if not cached:
|
if not cached:
|
||||||
|
|
|
@ -16,10 +16,17 @@ def add_topic_stat_columns(q):
|
||||||
aliased_shout = aliased(Shout)
|
aliased_shout = aliased(Shout)
|
||||||
|
|
||||||
q = (
|
q = (
|
||||||
q.outerjoin(aliased_shout_topic, and_(aliased_shout_topic.topic == Topic.id, aliased_shout.published_at.is_not(None)))
|
q.outerjoin(aliased_shout_topic, aliased_shout_topic.topic == Topic.id)
|
||||||
.add_columns(
|
.add_columns(
|
||||||
func.count(distinct(aliased_shout_topic.shout)).label('shouts_stat')
|
func.count(distinct(aliased_shout_topic.shout)).label('shouts_stat')
|
||||||
)
|
)
|
||||||
|
.outerjoin(
|
||||||
|
aliased_shout_author,
|
||||||
|
and_(
|
||||||
|
aliased_shout_topic.shout == aliased_shout_author.shout,
|
||||||
|
aliased_shout.published_at.is_not(None),
|
||||||
|
)
|
||||||
|
)
|
||||||
.outerjoin(
|
.outerjoin(
|
||||||
aliased_shout_author,
|
aliased_shout_author,
|
||||||
aliased_shout_topic.shout == aliased_shout_author.shout,
|
aliased_shout_topic.shout == aliased_shout_author.shout,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user