diff --git a/migration/tables/comments.py b/migration/tables/comments.py index 88c41216..82e32924 100644 --- a/migration/tables/comments.py +++ b/migration/tables/comments.py @@ -180,6 +180,7 @@ async def migrate(entry, storage): def migrate_2stage(old_comment, idmap): if old_comment.get('body'): new_id = idmap.get(old_comment.get('oid')) + new_id = idmap.get(old_comment.get('_id')) if new_id: new_replyto_id = None old_replyto_id = old_comment.get("replyTo") diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index 7c61035b..a04e57ec 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -225,32 +225,32 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0): :return: Reaction[] """ - CreatedByUser = aliased(User) - ReactedShout = aliased(Shout) q = select( - Reaction, CreatedByUser, ReactedShout + Reaction, User, Shout ).join( - CreatedByUser, Reaction.createdBy == CreatedByUser.id + User, Reaction.createdBy == User.id ).join( - ReactedShout, Reaction.shout == ReactedShout.id + Shout, Reaction.shout == Shout.id ) if by.get("shout"): - aliased_shout = aliased(Shout) - q = q.join(aliased_shout).filter(aliased_shout.slug == by["shout"]) + q = q.filter(Shout.slug == by["shout"]) elif by.get("shouts"): - aliased_shout = aliased(Shout) - q = q.join(aliased_shout).filter(aliased_shout.shout.in_(by["shouts"])) + q = q.filter(Shout.shout.in_(by["shouts"])) + if by.get("createdBy"): - aliased_user = aliased(User) - q = q.join(aliased_user).filter(aliased_user.slug == by.get("createdBy")) + q = q.filter(User.slug == by.get("createdBy")) + if by.get("topic"): # TODO: check q = q.filter(Shout.topics.contains(by["topic"])) + if by.get("comment"): q = q.filter(func.length(Reaction.body) > 0) + if len(by.get('search', '')) > 2: q = q.filter(Reaction.body.ilike(f'%{by["body"]}%')) + if by.get("days"): after = datetime.now(tz=timezone.utc) - timedelta(days=int(by["days"]) or 30) q = q.filter(Reaction.createdAt > after) @@ -259,7 +259,7 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0): order_field = by.get("sort", "").replace('-', '') or Reaction.createdAt q = q.group_by( - Reaction.id, CreatedByUser.id, ReactedShout.id + Reaction.id, User.id, Shout.id ).order_by( order_way(order_field) ) diff --git a/schema.graphql b/schema.graphql index 7d7729ca..98b82af4 100644 --- a/schema.graphql +++ b/schema.graphql @@ -50,6 +50,7 @@ type Author { userpic: String caption: String # only for full shout bio: String + about: String links: [String] stat: AuthorStat roles: [Role] # in different communities