comment-ratings
All checks were successful
Deploy on push / deploy (push) Successful in 1m31s

This commit is contained in:
Untone 2024-07-22 11:32:47 +03:00
parent a43a44302b
commit a4411cfa34
5 changed files with 52 additions and 5 deletions

View File

@ -1,3 +1,8 @@
[0.4.2]
- reactions load resolvers separated for ratings (no stats) and comments
- reactions stats improved
- load_comment_ratings separate resolver
[0.4.1] [0.4.1]
- follow/unfollow logic updated and unified with cache - follow/unfollow logic updated and unified with cache

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "core" name = "core"
version = "0.4.1" version = "0.4.2"
description = "core module for discours.io" description = "core module for discours.io"
authors = ["discoursio devteam"] authors = ["discoursio devteam"]
license = "MIT" license = "MIT"

View File

@ -27,7 +27,8 @@ from resolvers.reaction import (
load_shouts_followed_by, load_shouts_followed_by,
update_reaction, update_reaction,
load_shout_comments, load_shout_comments,
load_shout_ratings load_shout_ratings,
load_comment_ratings,
) )
from resolvers.reader import ( from resolvers.reader import (
get_shout, get_shout,
@ -102,6 +103,7 @@ __all__ = [
"load_reactions_by", "load_reactions_by",
"load_shout_comments", "load_shout_comments",
"load_shout_ratings", "load_shout_ratings",
"load_comment_ratings",
# notifier # notifier
"load_notifications", "load_notifications",
"notifications_seen_thread", "notifications_seen_thread",

View File

@ -379,7 +379,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
:after - amount of time ago :after - amount of time ago
:sort - a fieldname to sort desc by default :sort - a fieldname to sort desc by default
} }
:param limit: int amount of shouts :param limit: int amount of reactions
:param offset: int offset in this order :param offset: int offset in this order
:return: Reaction[] :return: Reaction[]
""" """
@ -528,7 +528,7 @@ async def load_shout_ratings(_, info, shout: int, limit=100, offset=0):
get paginated reactions with no stats get paginated reactions with no stats
:param info: graphql meta :param info: graphql meta
:param shout: int shout id :param shout: int shout id
:param limit: int amount of shouts :param limit: int amount of reactions
:param offset: int offset in this order :param offset: int offset in this order
:return: Reaction[] :return: Reaction[]
""" """
@ -567,7 +567,7 @@ async def load_shout_comments(_, info, shout: int, limit=50, offset=0):
getting paginated comments with stats getting paginated comments with stats
:param info: graphql meta :param info: graphql meta
:param shout: int shout id :param shout: int shout id
:param limit: int amount of shouts :param limit: int amount of reactions
:param offset: int offset in this order :param offset: int offset in this order
:return: Reaction[] :return: Reaction[]
""" """
@ -612,3 +612,42 @@ async def load_shout_comments(_, info, shout: int, limit=50, offset=0):
reactions.add(reaction) reactions.add(reaction)
return reactions return reactions
@query.field("load_comment_ratings")
async def load_comment_ratings(_, info, comment: int, limit=100, offset=0):
"""
get paginated reactions with no stats
:param info: graphql meta
:param comment: int comment id
:param limit: int amount of reactions
:param offset: int offset in this order
:return: Reaction[]
"""
q = (
select(Reaction, Author, Shout)
.select_from(Reaction)
.join(Author, Reaction.created_by == Author.id)
.join(Shout, Reaction.shout == Shout.id)
)
# filter, group, order, limit, offset
q = q.filter(and_(Reaction.deleted_at.is_(None), Reaction.reply_to == comment, Reaction.kind.in_(RATING_REACTIONS)))
q = q.group_by(Reaction.id)
q = q.order_by(desc(Reaction.created_at))
q = q.limit(limit).offset(offset)
reactions = set()
with local_session() as session:
result_rows = session.execute(q)
for [
reaction,
author,
shout,
] in result_rows:
reaction.created_by = author
reaction.shout = shout
reactions.add(reaction)
return reactions

View File

@ -29,6 +29,7 @@ type Query {
load_shouts_by(options: LoadShoutsOptions): [Shout] load_shouts_by(options: LoadShoutsOptions): [Shout]
load_shout_comments(shout: Int!, limit: Int, offset: Int): [Reaction] load_shout_comments(shout: Int!, limit: Int, offset: Int): [Reaction]
load_shout_ratings(shout: Int!, limit: Int, offset: Int): [Reaction] load_shout_ratings(shout: Int!, limit: Int, offset: Int): [Reaction]
load_comment_ratings(shout: Int!, limit: Int, offset: Int): [Reaction]
load_shouts_search(text: String!, limit: Int, offset: Int): [SearchResult] load_shouts_search(text: String!, limit: Int, offset: Int): [SearchResult]
load_shouts_feed(options: LoadShoutsOptions): [Shout] load_shouts_feed(options: LoadShoutsOptions): [Shout]
load_shouts_unrated(limit: Int, offset: Int): [Shout] load_shouts_unrated(limit: Int, offset: Int): [Shout]