forked from mtusi2026/mtusi2026lab2
Исправление по замечанию: кэш сессий наполняется после промаха
This commit is contained in:
+4
-8
@@ -7,7 +7,7 @@ from typing import Optional
|
||||
|
||||
import valkey.asyncio as valkey
|
||||
|
||||
from app import config
|
||||
from app import config, repo
|
||||
from app.cursor import fmt
|
||||
from app.errors import unavailable
|
||||
|
||||
@@ -74,12 +74,7 @@ class SessionStore:
|
||||
row = await cur.fetchone()
|
||||
if row is None:
|
||||
return None
|
||||
user = {
|
||||
"id": str(row["id"]),
|
||||
"username": row["username"],
|
||||
"display_name": row["display_name"],
|
||||
"created_at": fmt(row["created_at"]),
|
||||
}
|
||||
user = repo.public_user(row)
|
||||
await self._cache_put(digest, user, row["expires_at"])
|
||||
return user
|
||||
|
||||
@@ -119,8 +114,9 @@ class SessionStore:
|
||||
ttl = self._cache_ttl(expires_at)
|
||||
if ttl <= 0:
|
||||
return
|
||||
payload = json.dumps(user)
|
||||
try:
|
||||
await self.client.set(self.key(digest), json.dumps(user), ex=ttl)
|
||||
await self.client.set(self.key(digest), payload, ex=ttl)
|
||||
except Exception:
|
||||
self._cache_failed("set")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user