shoutscache, format

This commit is contained in:
2022-09-07 19:19:06 +03:00
parent 742042398c
commit 365c2f25e7
9 changed files with 129 additions and 33 deletions

View File

@@ -9,14 +9,14 @@ from sqlalchemy import and_
@mutation.field("createCollection")
@login_required
async def create_collection(_, info, input):
async def create_collection(_, _info, inp):
# auth = info.context["request"].auth
# user_id = auth.user_id
collection = Collection.create(
slug=input.get("slug", ""),
title=input.get("title", ""),
desc=input.get("desc", ""),
pic=input.get("pic", ""),
slug=inp.get("slug", ""),
title=inp.get("title", ""),
desc=inp.get("desc", ""),
pic=inp.get("pic", ""),
)
return {"collection": collection}
@@ -24,7 +24,7 @@ async def create_collection(_, info, input):
@mutation.field("updateCollection")
@login_required
async def update_collection(_, info, input):
async def update_collection(_, info, inp):
auth = info.context["request"].auth
user_id = auth.user_id
collection_slug = input.get("slug", "")
@@ -38,9 +38,9 @@ async def update_collection(_, info, input):
return {"error": "invalid collection id"}
if collection.createdBy not in (owner + editors):
return {"error": "access denied"}
collection.title = input.get("title", "")
collection.desc = input.get("desc", "")
collection.pic = input.get("pic", "")
collection.title = inp.get("title", "")
collection.desc = inp.get("desc", "")
collection.pic = inp.get("pic", "")
collection.updatedAt = datetime.now()
session.commit()
@@ -63,7 +63,7 @@ async def delete_collection(_, info, slug):
@query.field("getUserCollections")
async def get_user_collections(_, info, userslug):
async def get_user_collections(_, _info, userslug):
collections = []
with local_session() as session:
user = session.query(User).filter(User.slug == userslug).first()

View File

@@ -58,10 +58,10 @@ def reactions_unfollow(user, slug):
async def create_reaction(_, info, inp):
user = info.context["request"].user
# TODO: filter allowed reaction kinds
# TODO: filter allowed for post reaction kinds
reaction = Reaction.create(**inp)
ReactedStorage.increment(reaction.shout, reaction.replyTo)
ReactedStorage.react(reaction)
try:
reactions_follow(user, inp["shout"], True)
except Exception as e:

View File

@@ -18,42 +18,42 @@ from sqlalchemy.orm import selectinload
@query.field("topViewed")
async def top_viewed(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.top_viewed[((page - 1) * size) : (page * size)]
return ShoutsCache.get_top_viewed[((page - 1) * size) : (page * size)]
@query.field("topMonth")
async def top_month(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.top_month[((page - 1) * size) : (page * size)]
return ShoutsCache.get_top_month[((page - 1) * size) : (page * size)]
@query.field("topOverall")
async def top_overall(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.top_overall[((page - 1) * size) : (page * size)]
return ShoutsCache.get_top_overall[((page - 1) * size) : (page * size)]
@query.field("recentPublished")
async def recent_published(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_published[((page - 1) * size) : (page * size)]
return ShoutsCache.get_recent_published[((page - 1) * size) : (page * size)]
@query.field("recentAll")
async def recent_all(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_all[((page - 1) * size) : (page * size)]
return ShoutsCache.get_recent_all[((page - 1) * size) : (page * size)]
@query.field("recentReacted")
async def recent_reacted(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_reacted[((page - 1) * size) : (page * size)]
return ShoutsCache.get_recent_reacted[((page - 1) * size) : (page * size)]
@mutation.field("viewShout")
async def view_shout(_, info, slug):
await ViewedStorage.inc_shout(slug)
await ViewedStorage.increment(slug)
return {"error": ""}