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,8 +123,13 @@ 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):
if SINGLE_COMMUNITY:
return recent_published(_, info, page, size)
else:
page = page - 1 page = page - 1
with local_session() as session: with local_session() as session:
#TODO fix postgres high load #TODO fix postgres high load

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
} }