From df224fc2096469b9422759dfffb1f15d9688e6b0 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Mon, 21 Nov 2022 07:36:40 +0300 Subject: [PATCH] -storage --- requirements.txt | 1 + resolvers/profile.py | 17 +++++++++++++---- services/stat/reacted.py | 2 +- services/zine/authors.py | 12 ------------ 4 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 services/zine/authors.py diff --git a/requirements.txt b/requirements.txt index e47130af..4b36b809 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,3 +25,4 @@ DateTime~=4.7 asyncio~=3.4.3 python-dateutil~=2.8.2 beautifulsoup4~=4.11.1 +lxml diff --git a/resolvers/profile.py b/resolvers/profile.py index 41af82f6..62b50e72 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -11,7 +11,6 @@ from orm.topic import Topic, TopicFollower from orm.user import AuthorFollower, Role, User, UserRating, UserRole from services.stat.reacted import ReactedStorage from services.stat.topicstat import TopicStat -from services.zine.authors import AuthorsStorage from services.zine.shoutauthor import ShoutAuthor # from .community import followed_communities @@ -175,12 +174,22 @@ def author_unfollow(user, slug): @query.field("authorsAll") async def get_authors_all(_, _info): - authors = await AuthorsStorage.get_all_authors() - for author in authors: - author.stat = await get_author_stat(author.slug) + with local_session() as session: + authors = session.query(User).join(ShoutAuthor).all() + for author in authors: + author.stat = await get_author_stat(author.slug) return authors +@query.field("getAuthor") +async def get_author(_, _info, slug): + with local_session() as session: + author = session.query(User).join(ShoutAuthor).where(User.slug == slug).first() + for author in author: + author.stat = await get_author_stat(author.slug) + return author + + @query.field("loadAuthorsBy") async def load_authors_by(_, info, by, limit, offset): authors = [] diff --git a/services/stat/reacted.py b/services/stat/reacted.py index e6a667dd..00f4fb66 100644 --- a/services/stat/reacted.py +++ b/services/stat/reacted.py @@ -182,7 +182,7 @@ class ReactedStorage: await self.recount(siblings) print("[stat.reacted] %d reactions recounted" % c) - print("[stat.reacted] %d shouts" % len(self.modified_shouts)) + print("[stat.reacted] %d shouts modified" % len(self.modified_shouts)) print("[stat.reacted] %d topics" % len(self.reacted["topics"].values())) print("[stat.reacted] %d authors" % len(self.reacted["authors"].values())) print("[stat.reacted] %d replies" % len(self.reacted["reactions"])) diff --git a/services/zine/authors.py b/services/zine/authors.py deleted file mode 100644 index b91e788e..00000000 --- a/services/zine/authors.py +++ /dev/null @@ -1,12 +0,0 @@ -from base.orm import local_session -from orm.user import User -from orm.shout import ShoutAuthor - - -class AuthorsStorage: - @staticmethod - async def get_all_authors(): - with local_session() as session: - query = session.query(User).join(ShoutAuthor) - result = query.all() - return result