From 8e7e0709482882c4693667bf19fc754f929d8da4 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sun, 12 Jun 2022 01:05:20 +0300 Subject: [PATCH] not published in feed. devmode try --- resolvers/__init__.py | 3 ++- resolvers/zine.py | 25 +++++++++++++++++++++++-- schema.graphql | 5 ++++- server.py | 9 ++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 3ec261df..658ae999 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -1,6 +1,6 @@ from resolvers.auth import login, sign_out, is_email_free, register, confirm from resolvers.zine import create_shout, get_shout_by_slug, \ - top_month, top_overall, recent_shouts, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \ + top_month, top_overall, recent_shouts, recent_all, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \ shouts_candidates, shouts_reviewed, shouts_subscribed from resolvers.profile import get_users_by_slugs, get_current_user from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \ @@ -20,6 +20,7 @@ __all__ = [ "get_users_by_slugs", "get_shout_by_slug", "recent_shouts", + "recent_all", "shouts_by_topics", "shouts_by_authors", "shouts_by_communities", diff --git a/resolvers/zine.py b/resolvers/zine.py index c74a0a68..f8e1dcf9 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -98,6 +98,21 @@ class ShoutsCache: async with ShoutsCache.lock: ShoutsCache.recent_shouts = shouts + @staticmethod + async def prepare_recent_all(): + with local_session() as session: + stmt = select(Shout).\ + options(selectinload(Shout.authors), selectinload(Shout.topics)).\ + where(Shout.publishedAt != None).\ + limit(ShoutsCache.limit) + shouts = [] + for row in session.execute(stmt): + shout = row.Shout + shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug) + shouts.append(shout) + async with ShoutsCache.lock: + ShoutsCache.recent_all = shouts + @staticmethod async def prepare_recent_commented(): with local_session() as session: @@ -184,6 +199,7 @@ class ShoutsCache: await ShoutsCache.prepare_top_overall() await ShoutsCache.prepare_top_viewed() await ShoutsCache.prepare_recent_shouts() + await ShoutsCache.prepare_recent_all() await ShoutsCache.prepare_recent_commented() print("shouts cache update finished") except Exception as err: @@ -225,13 +241,18 @@ async def top_overall(_, info, page, size): async with ShoutsCache.lock: return ShoutsCache.top_overall[(page - 1) * size : page * size] -@query.field("recents") +@query.field("recentPublished") async def recent_shouts(_, info, page, size): async with ShoutsCache.lock: return ShoutsCache.recent_shouts[(page - 1) * size : page * size] +@query.field("recentAll") +async def recent_all(_, info, page, size): + async with ShoutsCache.lock: + return ShoutsCache.recent_all[(page - 1) * size : page * size] + @query.field("recentCommented") -async def recent_shouts(_, info, page, size): +async def recent_commented(_, info, page, size): async with ShoutsCache.lock: return ShoutsCache.recent_commented[(page - 1) * size : page * size] diff --git a/schema.graphql b/schema.graphql index d837e30f..dccda6a2 100644 --- a/schema.graphql +++ b/schema.graphql @@ -166,7 +166,10 @@ type Query { topViewed(page: Int!, size: Int!): [Shout]! topMonth(page: Int!, size: Int!): [Shout]! topOverall(page: Int!, size: Int!): [Shout]! - recents(page: Int!, size: Int!): [Shout]! + recentPublished(page: Int!, size: Int!): [Shout]! + + # feed + recentAll(page: Int!, size: Int!): [Shout]! # topics topicsBySlugs(slugs: [String]): [Topic]! diff --git a/server.py b/server.py index fd3514f7..9d7ffaff 100644 --- a/server.py +++ b/server.py @@ -8,7 +8,14 @@ if __name__ == '__main__': inbox_service = len(sys.argv) > 1 and sys.argv[1] == "inbox" if dev_mode: print("DEV MODE") - uvicorn.run("main:app", host="0.0.0.0", port=8080, ssl_keyfile="discours.key", ssl_certfile="discours.crt", reload=True) + headers = [ + ("Access-Control-Allow-Methods", "GET, POST, OPTIONS, HEAD"), + ("Access-Control-Allow-Origin", "*"), + ("Access-Control-Allow-Headers", "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"), + ("Access-Control-Expose-Headers", "Content-Length,Content-Range"), + ("Access-Control-Allow-Credentials", "true") + ] + uvicorn.run("main:app", host="localhost", port=8080, headers=headers) #, ssl_keyfile="discours.key", ssl_certfile="discours.crt", reload=True) elif inbox_service: print("INBOX SERVICE") uvicorn.run("inbox_main:app", host="0.0.0.0", port=INBOX_SERVICE_PORT)