Merge branch 'main' of github.com:Discours/discours-backend into viewed

This commit is contained in:
2022-11-22 08:04:14 +03:00
10 changed files with 31 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
import asyncio
from sqlalchemy.orm import selectinload
from orm.user import User
from base.orm import local_session
class UserStorage:
@@ -20,9 +21,15 @@ class UserStorage:
@staticmethod
async def get_user(id):
self = UserStorage
async with self.lock:
return self.users.get(id)
with local_session() as session:
user = (
session.query(User)
.options(selectinload(User.roles), selectinload(User.ratings))
.filter(User.id == id)
.one()
)
return user
@staticmethod
async def get_all_users():

View File

@@ -36,7 +36,8 @@ class ReactedStorage:
@staticmethod
async def get_shout_stat(slug):
return {
"viewed": await ViewedStorage.get_shout(slug),
# TODO
"viewed": 0, # await ViewedStorage.get_shout(slug),
"reacted": len(await ReactedStorage.get_shout(slug)),
"commented": len(await ReactedStorage.get_comments(slug)),
"rating": await ReactedStorage.get_rating(slug),