From 00181e7114ec1283ebcdec90c9f6a2209ce2e48b Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 7 Sep 2022 22:36:40 +0300 Subject: [PATCH] fixes-done --- services/stat/reacted.py | 2 +- services/stat/topicstat.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/services/stat/reacted.py b/services/stat/reacted.py index b8bdb066..077cef0e 100644 --- a/services/stat/reacted.py +++ b/services/stat/reacted.py @@ -88,7 +88,7 @@ class ReactedStorage: self = ReactedStorage async with self.lock: return list( - filter(lambda r: r.comment, self.reacted["topics"].get(topic_slug, {})) + filter(lambda r: r.comment, self.reacted["topics"].get(topic_slug, [])) ) @staticmethod diff --git a/services/stat/topicstat.py b/services/stat/topicstat.py index 58c75460..6ecf0a3b 100644 --- a/services/stat/topicstat.py +++ b/services/stat/topicstat.py @@ -6,6 +6,15 @@ from services.zine.shoutauthor import ShoutAuthorStorage from orm.topic import ShoutTopic, TopicFollower +def unique(list1): + + # insert the list to the set + list_set = set(list1) + # convert the set to the list + unique_list = (list(list_set)) + return unique_list + + class TopicStat: shouts_by_topic = {} authors_by_topic = {} @@ -16,23 +25,17 @@ class TopicStat: @staticmethod async def load_stat(session): self = TopicStat - self.shouts_by_topic = {} - self.authors_by_topic = {} shout_topics = session.query(ShoutTopic).all() for shout_topic in shout_topics: topic = shout_topic.topic shout = shout_topic.shout if not self.shouts_by_topic.get(topic): self.shouts_by_topic[topic] = [] - if shout not in self.shouts_by_topic[topic]: - self.shouts_by_topic[topic].append(shout) - + self.shouts_by_topic[topic].append(shout) authors = await ShoutAuthorStorage.get_authors(shout) - if topic in self.authors_by_topic: - self.authors_by_topic[topic].update(authors) - else: - self.authors_by_topic[topic] = list(set(authors)) - + if not self.authors_by_topic.get(topic): + self.authors_by_topic[topic] = [] + self.authors_by_topic[topic] = unique(self.authors_by_topic[topic] + authors) print("[stat.topics] authors sorted") print("[stat.topics] shouts sorted")