Исправление по замечанию: кэш сессий наполняется после промаха

This commit is contained in:
alenchha
2026-10-23 17:42:38 +03:00
parent a0c16afa33
commit 1a60b9cd1f
16 changed files with 263 additions and 194 deletions
+4 -8
View File
@@ -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")