v1.7.1: fix all P1-P4, C1-C6, H1-H6, M1-M7, L1-L3 from error.md — async migrations, CSS variables, SQL validation, event loop, prompt injection, VCF parsing, race conditions, unused imports, gitignore
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from typing import Optional, Dict
|
||||
from sqlalchemy import select
|
||||
from app.database import async_session
|
||||
@@ -8,13 +9,17 @@ class SettingsCache:
|
||||
def __init__(self):
|
||||
self._cache: dict[str, str] = {}
|
||||
self._loaded = False
|
||||
self._lock = asyncio.Lock()
|
||||
|
||||
async def _load(self):
|
||||
async with async_session() as db:
|
||||
result = await db.execute(select(BotSetting))
|
||||
rows = result.scalars().all()
|
||||
self._cache = {row.key: row.value or "" for row in rows}
|
||||
self._loaded = True
|
||||
async with self._lock:
|
||||
if self._loaded:
|
||||
return
|
||||
async with async_session() as db:
|
||||
result = await db.execute(select(BotSetting))
|
||||
rows = result.scalars().all()
|
||||
self._cache = {row.key: row.value or "" for row in rows}
|
||||
self._loaded = True
|
||||
|
||||
async def get(self, key: str, default: str = "") -> str:
|
||||
if not self._loaded:
|
||||
|
||||
Reference in New Issue
Block a user