diff --git a/main.py b/main.py index 5c0f2120..9d652939 100644 --- a/main.py +++ b/main.py @@ -83,6 +83,8 @@ app.mount( GraphQL(schema, debug=True), ) +print("[main] app mounted") + dev_app = app = Starlette( debug=True, on_startup=[dev_start_up], diff --git a/resolvers/load.py b/resolvers/load.py index 2444cd41..dcc1a66b 100644 --- a/resolvers/load.py +++ b/resolvers/load.py @@ -1,13 +1,23 @@ from datetime import datetime, timedelta, timezone +from sqlalchemy.engine import ObjectKind from sqlalchemy.orm import joinedload, aliased -from sqlalchemy.sql.expression import desc, asc, select, func, case, and_, nulls_last +from sqlalchemy.sql.expression import ( + desc, + asc, + select, + func, + case, + and_, + # text, + nulls_last, +) from auth.authenticate import login_required from auth.credentials import AuthCredentials -from services.exceptions import ObjectNotExist -from services.db import local_session -from services.schema import query +from base.exceptions import ObjectNotExist # , OperationNotAllowed +from base.orm import local_session +from base.resolvers import query from orm import TopicFollower from orm.reaction import Reaction, ReactionKind from orm.shout import Shout, ShoutAuthor, ShoutTopic @@ -96,14 +106,15 @@ async def load_shout(_, info, slug=None, shout_id=None): q = q.filter(Shout.deletedAt.is_(None)).group_by(Shout.id) - try: + resp = session.execute(q).first() + if resp: [ shout, reacted_stat, commented_stat, rating_stat, last_comment, - ] = session.execute(q).first() + ] = resp shout.stat = { "viewed": shout.views, @@ -119,8 +130,9 @@ async def load_shout(_, info, slug=None, shout_id=None): if author.id == author_caption.user: author.caption = author_caption.caption return shout - except Exception: - raise ObjectNotExist("Slug was not found: %s" % slug) + else: + print("Slug was not found: %s" % slug) + return @query.field("loadShouts") diff --git a/services/viewed.py b/services/viewed.py index 634ef32f..7ae9b5a0 100644 --- a/services/viewed.py +++ b/services/viewed.py @@ -75,8 +75,7 @@ class ViewedStorage: {"Authorization": "Bearer %s" % str(token)}, schema=schema_str ) print( - "[stat] * authorized permanentely by ackee.discours.io: %s" - % token + "[stat] * authorized permanentely by ackee.discours.io: %s" % token ) else: print("[stat] * please set ACKEE_TOKEN") @@ -171,16 +170,18 @@ class ViewedStorage: if viewer == "old-discours": # this is needed for old db migration if shout.viewsOld == amount: - print(f"[stat] viewsOld amount: {amount}") + print(f"[stat] ⎪ viewsOld amount: {amount}") else: - print(f"[stat] viewsOld amount changed: {shout.viewsOld} --> {amount}") + print( + f"[stat] ⎪ viewsOld amount changed: {shout.viewsOld} --> {amount}" + ) shout.viewsOld = amount else: if shout.viewsAckee == amount: - print(f"[stat] viewsAckee amount: {amount}") + print(f"[stat] ⎪ viewsAckee amount: {amount}") else: print( - f"[stat] viewsAckee amount changed: {shout.viewsAckee} --> {amount}" + f"[stat] ⎪ viewsAckee amount changed: {shout.viewsAckee} --> {amount}" ) shout.viewsAckee = amount