From 34d04e42400a66569e7f6b629ca9deb28c41d71c Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Tue, 31 Oct 2023 14:52:58 +0100 Subject: [PATCH] my feed query fixed --- README.md | 23 +++++++++++++---------- resolvers/zine/load.py | 17 +++++++++++------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7081fbca..12e902db 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,6 @@ - starlette - uvicorn -# Local development - -Install deps first - on osx ``` brew install redis nginx postgres @@ -22,16 +18,23 @@ on debian/ubuntu apt install redis nginx ``` -First, install Postgres. Then you'll need some data, so migrate it: +# Local development + +Install deps first + ``` -createdb discoursio -python server.py migrate +pip install -r requirements.txt +pip install -r requirements-dev.txt +pre-commit install ``` -Then run nginx, redis and API server +Create database from backup +``` +./restdb.sh +``` + +Start local server ``` -redis-server -pip install -r requirements.txt python3 server.py dev ``` diff --git a/resolvers/zine/load.py b/resolvers/zine/load.py index 95fac914..186fe347 100644 --- a/resolvers/zine/load.py +++ b/resolvers/zine/load.py @@ -210,12 +210,17 @@ async def get_my_feed(_, info, options): auth: AuthCredentials = info.context["request"].auth user_id = auth.user_id + user_followed_authors = select(AuthorFollower.author).where(AuthorFollower.follower == user_id) + user_followed_topics = select(TopicFollower.topic).where(TopicFollower.follower == user_id) + subquery = ( select(Shout.id) - .join(ShoutAuthor) - .join(AuthorFollower, AuthorFollower.follower == user_id) - .join(ShoutTopic) - .join(TopicFollower, TopicFollower.follower == user_id) + .where(Shout.id == ShoutAuthor.shout) + .where(Shout.id == ShoutTopic.shout) + .where( + (ShoutAuthor.user.in_(user_followed_authors)) + | (ShoutTopic.topic.in_(user_followed_topics)) + ) ) q = ( @@ -240,9 +245,10 @@ async def get_my_feed(_, info, options): q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset) + # print(q.compile(compile_kwargs={"literal_binds": True})) + shouts = [] with local_session() as session: - shouts_map = {} for [shout, reacted_stat, commented_stat, rating_stat, last_comment] in session.execute( q ).unique(): @@ -253,6 +259,5 @@ async def get_my_feed(_, info, options): "commented": commented_stat, "rating": rating_stat, } - shouts_map[shout.id] = shout return shouts