Merge branch 'fast-random-topics' into 'main'
Fast random topics See merge request discoursio/discoursio-api!13
This commit is contained in:
commit
1f08f5a66d
|
@ -201,13 +201,14 @@ async def create_reaction(_, info, reaction={}):
|
|||
|
||||
@mutation.field("updateReaction")
|
||||
@login_required
|
||||
async def update_reaction(_, info, reaction={}):
|
||||
async def update_reaction(_, info, id, reaction={}):
|
||||
auth: AuthCredentials = info.context["request"].auth
|
||||
|
||||
with local_session() as session:
|
||||
user = session.query(User).where(User.id == auth.user_id).first()
|
||||
q = select(Reaction).filter(Reaction.id == reaction['id'])
|
||||
q = select(Reaction).filter(Reaction.id == id)
|
||||
q = add_reaction_stat_columns(q)
|
||||
q = q.group_by(Reaction.id)
|
||||
|
||||
[r, reacted_stat, commented_stat, rating_stat] = session.execute(q).unique().one()
|
||||
|
||||
|
@ -235,12 +236,12 @@ async def update_reaction(_, info, reaction={}):
|
|||
|
||||
@mutation.field("deleteReaction")
|
||||
@login_required
|
||||
async def delete_reaction(_, info, reaction=None):
|
||||
async def delete_reaction(_, info, id):
|
||||
# NOTE: reaction is id
|
||||
auth: AuthCredentials = info.context["request"].auth
|
||||
|
||||
with local_session() as session:
|
||||
r = session.query(Reaction).filter(Reaction.id == reaction).first()
|
||||
r = session.query(Reaction).filter(Reaction.id == id).first()
|
||||
if not r:
|
||||
return {"error": "invalid reaction id"}
|
||||
if r.createdBy != auth.user_id:
|
||||
|
|
|
@ -145,8 +145,14 @@ def topic_unfollow(user_id, slug):
|
|||
@query.field("topicsRandom")
|
||||
async def topics_random(_, info, amount=12):
|
||||
q = select(Topic)
|
||||
q = add_topic_stat_columns(q)
|
||||
q = q.join(ShoutTopic)
|
||||
q = q.group_by(Topic.id)
|
||||
q = q.having(func.count(distinct(ShoutTopic.shout)) > 2)
|
||||
q = q.order_by(func.random()).limit(amount)
|
||||
|
||||
return get_topics_from_query(q)
|
||||
topics = []
|
||||
with local_session() as session:
|
||||
for [topic] in session.execute(q):
|
||||
topics.append(topic)
|
||||
|
||||
return topics
|
||||
|
|
|
@ -198,8 +198,8 @@ type Mutation {
|
|||
|
||||
# reactions
|
||||
createReaction(reaction: ReactionInput!): Result!
|
||||
updateReaction(reaction: ReactionInput!): Result!
|
||||
deleteReaction(reaction: Int!): Result!
|
||||
updateReaction(id: Int!, reaction: ReactionInput!): Result!
|
||||
deleteReaction(id: Int!): Result!
|
||||
|
||||
# draft / collab
|
||||
createDraft(draft: DraftInput!): Result!
|
||||
|
|
Loading…
Reference in New Issue
Block a user