counters fixes

This commit is contained in:
tonyrewin 2022-08-17 10:59:17 +03:00
parent ab9d03aac6
commit 04aaaab609
5 changed files with 32 additions and 29 deletions

View File

@ -22,10 +22,9 @@ class Reaction(Base):
@property @property
async def stat(self): async def stat(self):
rrr = await ReactedStorage.get_reaction(self.id)
print(rrr[0])
return { return {
"viewed": await ViewedStorage.get_reaction(self.id), "viewed": await ViewedStorage.get_reaction(self.id),
"reacted": len(rrr), "reacted": len(await ReactedStorage.get_reaction(self.id)),
"rating": await ReactedStorage.get_reaction_rating(self.id) "rating": await ReactedStorage.get_reaction_rating(self.id),
"commented": len(await ReactedStorage.get_reaction_comments(self.id))
} }

View File

@ -63,9 +63,10 @@ class Shout(Base):
@property @property
async def stat(self): async def stat(self):
rrr = await ReactedStorage.get_shout(self.slug)
return { return {
"viewed": await ViewedStorage.get_shout(self.slug), "viewed": await ViewedStorage.get_shout(self.slug),
"reacted": len(rrr), "reacted": len(await ReactedStorage.get_shout(self.slug)),
"rating": await ReactedStorage.get_rating(self.slug) "commented": len(await ReactedStorage.get_comments(self.slug)),
"rating": await ReactedStorage.get_rating(self.slug),
"bookmarked": len(await ReactedStorage.get_bookmarked(self.slug))
} }

View File

@ -1,4 +0,0 @@
SELECT s.*, a.*, sa.* FROM shout s
JOIN shout_author sa ON s.slug = sa.shout
JOIN user a ON a.slug = sa.user
WHERE sa.slug = a.slug AND a.slug = %s;

View File

@ -123,25 +123,30 @@ async def shouts_by_authors(_, info, slugs, page, size):
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug) a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
return shouts return shouts
SINGLE_COMMUNITY = True
@query.field("shoutsByCommunities") @query.field("shoutsByCommunities")
async def shouts_by_communities(_, info, slugs, page, size): async def shouts_by_communities(_, info, slugs, page, size):
page = page - 1 if SINGLE_COMMUNITY:
with local_session() as session: return recent_published(_, info, page, size)
#TODO fix postgres high load else:
shouts = session.query(Shout).distinct().\ page = page - 1
join(ShoutTopic).\ with local_session() as session:
where(and_(Shout.publishedAt != None,\ #TODO fix postgres high load
ShoutTopic.topic.in_(\ shouts = session.query(Shout).distinct().\
select(Topic.slug).where(Topic.community.in_(slugs))\ join(ShoutTopic).\
))).\ where(and_(Shout.publishedAt != None,\
order_by(desc(Shout.publishedAt)).\ ShoutTopic.topic.in_(\
limit(size).\ select(Topic.slug).where(Topic.community.in_(slugs))\
offset(page * size) ))).\
order_by(desc(Shout.publishedAt)).\
for s in shouts: limit(size).\
for a in s.authors: offset(page * size)
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
return shouts for s in shouts:
for a in s.authors:
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
return shouts
@mutation.field("follow") @mutation.field("follow")
@login_required @login_required

View File

@ -412,6 +412,7 @@ type Stat {
viewed: Int viewed: Int
reacted: Int reacted: Int
rating: Int rating: Int
commented: Int
bookmarked: Int bookmarked: Int
} }
@ -440,6 +441,7 @@ type TopicStat {
authors: Int! authors: Int!
viewed: Int! viewed: Int!
reacted: Int! reacted: Int!
commented: Int
rating: Int rating: Int
} }