update schema

This commit is contained in:
Tony 2022-02-03 10:36:39 +03:00
parent dcdfdf7dc3
commit 6b255cc984
3 changed files with 21 additions and 26 deletions

View File

@ -1,7 +1,8 @@
from resolvers.auth import login, sign_out, is_email_free, register, confirm
from resolvers.inbox import create_message, delete_message, update_message, get_messages
from resolvers.zine import create_shout, get_shout_by_slug, top_month, top_overall, \
recent_shouts, top_viewed #, top_authors
recent_shouts, top_viewed, shouts_by_author, shouts_by_topic, \
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, \
topics_by_community, topics_by_slugs
@ -24,6 +25,11 @@ __all__ = [
"get_users_by_slugs",
"get_shout_by_slug",
"recent_shouts",
"shouts_by_topic",
"shouts_by_author",
"shouts_subscribed",
"shouts_reviewed",
"shouts_candidates",
"top_month",
"top_overall",
"top_viewed",

View File

@ -398,21 +398,17 @@ async def shouts_by_community(_, info, community, page, size):
offset(page * size)
return shouts
@query.field("shoutsByUserSubscriptions")
async def shouts_by_user_subscriptions(_, info, userSlug, page, size):
user = await UserStorage.get_user_by_slug(userSlug)
if not user:
return
@query.field("shoutsSubscribed")
async def shouts_subscribed(_, info, page, size):
with local_session() as session:
shouts_by_topic = session.query(Shout).\
join(ShoutTopic).\
join(TopicSubscription, ShoutTopic.topic == TopicSubscription.topic).\
where(and_(Shout.publishedAt != None, TopicSubscription.subscriber == userSlug))
where(and_(Shout.publishedAt != None, TopicSubscription.subscriber == User.slug))
shouts_by_author = session.query(Shout).\
join(ShoutAuthor).\
join(AuthorSubscription, ShoutAuthor.user == AuthorSubscription.author).\
where(and_(Shout.publishedAt != None, AuthorSubscription.subscriber == userSlug))
where(and_(Shout.publishedAt != None, AuthorSubscription.subscriber == User.slug))
shouts = shouts_by_topic.union(shouts_by_author).\
order_by(desc(Shout.publishedAt)).\
limit(size).\
@ -420,19 +416,16 @@ async def shouts_by_user_subscriptions(_, info, userSlug, page, size):
return shouts
@query.field("shoutsByUserRatingOrComment")
async def shouts_by_user_rating_or_comment(_, info, userSlug, page, size):
user = await UserStorage.get_user_by_slug(userSlug)
if not user:
return
@query.field("shoutsReviewed")
async def shouts_reviewed(_, info, page, size):
with local_session() as session:
shouts_by_rating = session.query(Shout).\
join(ShoutRating).\
where(and_(Shout.publishedAt != None, ShoutRating.rater == userSlug))
where(and_(Shout.publishedAt != None, ShoutRating.rater == User.slug))
shouts_by_comment = session.query(Shout).\
join(Comment).\
where(and_(Shout.publishedAt != None, Comment.author == user.id))
where(and_(Shout.publishedAt != None, Comment.author == User.id))
shouts = shouts_by_rating.union(shouts_by_comment).\
order_by(desc(Shout.publishedAt)).\
limit(size).\
@ -440,17 +433,13 @@ async def shouts_by_user_rating_or_comment(_, info, userSlug, page, size):
return shouts
@query.field("newShoutsWithoutRating")
async def new_shouts_without_rating(_, info, userSlug, size):
user = await UserStorage.get_user_by_slug(userSlug)
if not user:
return
@query.field("shoutsCandidates")
async def shouts_candidates(_, info, size):
#TODO: postgres heavy load
with local_session() as session:
shouts = session.query(Shout).distinct().\
outerjoin(ShoutRating).\
where(and_(Shout.publishedAt != None, ShoutRating.rater != userSlug)).\
where(and_(Shout.publishedAt != None, ShoutRating.rater != User.slug)).\
order_by(desc(Shout.publishedAt)).\
limit(size)

View File

@ -197,9 +197,9 @@ type Query {
getCommunity(slug: String): Community!
getCommunities: [Community]!
shoutsByUserSubscriptions(userSlug: String!, page: Int!, size: Int!): [Shout]!
shoutsByUserRatingOrComment(userSlug: String!, page: Int!, size: Int!): [Shout]!
newShoutsWithoutRating(userSlug: String!, size: Int = 10): [Shout]!
shoutsSubscribed(page: Int!, size: Int!): [Shout]!
shoutsReviewed(page: Int!, size: Int!): [Shout]!
shoutsCandidates(size: Int = 10): [Shout]!
}
############################################ Subscription