Improved caching and utils structure

This commit is contained in:
2025-04-22 23:22:01 +02:00
parent ec094f9a98
commit 5230ac9ace
15 changed files with 65 additions and 40 deletions

View File

@@ -8,7 +8,7 @@ from pymongo.results import InsertOneResult
from classes.errors.pycord_user import UserNotFoundError
from modules.database import col_users
from modules.logging_utils import get_logger
from modules.utils import get_logger, restore_from_cache
logger: Logger = get_logger(__name__)
@@ -41,11 +41,10 @@ class PycordUser:
Raises:
UserNotFoundError: User was not found and creation was not allowed
"""
if cache is not None:
cached_entry: Dict[str, Any] | None = cache.get_json(f"{cls.__short_name__}_{user_id}")
cached_entry: Dict[str, Any] | None = restore_from_cache(cls.__short_name__, user_id, cache=cache)
if cached_entry is not None:
return cls(**cached_entry)
if cached_entry is not None:
return cls(**cached_entry)
db_entry = await cls.__collection__.find_one({"id": user_id})