auth and minor fixes

This commit is contained in:
Igor Lobanov
2022-11-22 04:11:26 +01:00
parent 9215facb75
commit 8963781ca3
9 changed files with 30 additions and 15 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),