counters fixes
This commit is contained in:
parent
ab9d03aac6
commit
04aaaab609
|
@ -22,10 +22,9 @@ class Reaction(Base):
|
|||
|
||||
@property
|
||||
async def stat(self):
|
||||
rrr = await ReactedStorage.get_reaction(self.id)
|
||||
print(rrr[0])
|
||||
return {
|
||||
"viewed": await ViewedStorage.get_reaction(self.id),
|
||||
"reacted": len(rrr),
|
||||
"rating": await ReactedStorage.get_reaction_rating(self.id)
|
||||
"reacted": len(await ReactedStorage.get_reaction(self.id)),
|
||||
"rating": await ReactedStorage.get_reaction_rating(self.id),
|
||||
"commented": len(await ReactedStorage.get_reaction_comments(self.id))
|
||||
}
|
||||
|
|
|
@ -63,9 +63,10 @@ class Shout(Base):
|
|||
|
||||
@property
|
||||
async def stat(self):
|
||||
rrr = await ReactedStorage.get_shout(self.slug)
|
||||
return {
|
||||
"viewed": await ViewedStorage.get_shout(self.slug),
|
||||
"reacted": len(rrr),
|
||||
"rating": await ReactedStorage.get_rating(self.slug)
|
||||
"viewed": await ViewedStorage.get_shout(self.slug),
|
||||
"reacted": len(await ReactedStorage.get_shout(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))
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -123,25 +123,30 @@ async def shouts_by_authors(_, info, slugs, page, size):
|
|||
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
||||
return shouts
|
||||
|
||||
SINGLE_COMMUNITY = True
|
||||
|
||||
@query.field("shoutsByCommunities")
|
||||
async def shouts_by_communities(_, info, slugs, page, size):
|
||||
page = page - 1
|
||||
with local_session() as session:
|
||||
#TODO fix postgres high load
|
||||
shouts = session.query(Shout).distinct().\
|
||||
join(ShoutTopic).\
|
||||
where(and_(Shout.publishedAt != None,\
|
||||
ShoutTopic.topic.in_(\
|
||||
select(Topic.slug).where(Topic.community.in_(slugs))\
|
||||
))).\
|
||||
order_by(desc(Shout.publishedAt)).\
|
||||
limit(size).\
|
||||
offset(page * size)
|
||||
|
||||
for s in shouts:
|
||||
for a in s.authors:
|
||||
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
||||
return shouts
|
||||
if SINGLE_COMMUNITY:
|
||||
return recent_published(_, info, page, size)
|
||||
else:
|
||||
page = page - 1
|
||||
with local_session() as session:
|
||||
#TODO fix postgres high load
|
||||
shouts = session.query(Shout).distinct().\
|
||||
join(ShoutTopic).\
|
||||
where(and_(Shout.publishedAt != None,\
|
||||
ShoutTopic.topic.in_(\
|
||||
select(Topic.slug).where(Topic.community.in_(slugs))\
|
||||
))).\
|
||||
order_by(desc(Shout.publishedAt)).\
|
||||
limit(size).\
|
||||
offset(page * size)
|
||||
|
||||
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")
|
||||
@login_required
|
||||
|
|
|
@ -412,6 +412,7 @@ type Stat {
|
|||
viewed: Int
|
||||
reacted: Int
|
||||
rating: Int
|
||||
commented: Int
|
||||
bookmarked: Int
|
||||
}
|
||||
|
||||
|
@ -440,6 +441,7 @@ type TopicStat {
|
|||
authors: Int!
|
||||
viewed: Int!
|
||||
reacted: Int!
|
||||
commented: Int
|
||||
rating: Int
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user