counters fix

This commit is contained in:
2022-08-17 12:07:32 +03:00
parent 1254b14163
commit 68fd4d9936
2 changed files with 7 additions and 5 deletions

View File

@@ -5,7 +5,6 @@ from services.stat.viewed import ViewedStorage
from services.zine.shoutauthor import ShoutAuthorStorage
from orm.topic import ShoutTopic, TopicFollower
from typing import Dict
class TopicStat:
shouts_by_topic = {}
authors_by_topic = {}
@@ -18,14 +17,14 @@ class TopicStat:
self = TopicStat
self.shouts_by_topic = {}
self.authors_by_topic = {}
shout_topics = session.query(ShoutTopic)
shout_topics = session.query(ShoutTopic).all()
for shout_topic in shout_topics:
topic = shout_topic.topic
shout = shout_topic.shout
if topic in self.shouts_by_topic:
self.shouts_by_topic[topic].append(shout)
else:
self.shouts_by_topic[topic] = [shout]
self.shouts_by_topic[topic] = [shout, ]
authors = await ShoutAuthorStorage.get_authors(shout)
if topic in self.authors_by_topic:
@@ -66,7 +65,9 @@ class TopicStat:
"authors" : len(authors),
"followers" : len(followers),
"viewed": await ViewedStorage.get_topic(topic),
"reacted" : await ReactedStorage.get_topic(topic),
"reacted" : len(await ReactedStorage.get_topic(topic)),
"commented": len(await ReactedStorage.get_topic_comments(topic)),
"bookmarked": len(await ReactedStorage.get_topic_bookmarked(topic)),
"rating" : await ReactedStorage.get_topic_rating(topic),
}