Add ProfileSyncMiddleware to keep user profile data updated in the database

- Integrated ProfileSyncMiddleware to ensure that user profile information (username, first_name, last_name) remains current in the database.
- Updated get_enhanced_user_statistics to use timezone-aware datetime for accurate SQL queries, preventing naive/aware comparison issues.
- Clarified comments in the user statistics function for better understanding of active user metrics and subscription handling.
This commit is contained in:
machka-pasla
2025-08-15 23:40:23 +03:00
parent 13a9e58e27
commit a75a1f483c
9 changed files with 227 additions and 7 deletions
+3
View File
@@ -20,6 +20,7 @@ from bot.middlewares.i18n import I18nMiddleware, get_i18n_instance, JsonI18n
from bot.middlewares.db_session import DBSessionMiddleware
from bot.middlewares.ban_check_middleware import BanCheckMiddleware
from bot.middlewares.action_logger_middleware import ActionLoggerMiddleware
from bot.middlewares.profile_sync import ProfileSyncMiddleware
from bot.routers import build_root_router
@@ -314,6 +315,8 @@ async def run_bot(settings_param: Settings):
dp.update.outer_middleware(
I18nMiddleware(i18n=i18n_instance, settings=settings_param)
)
# Keep profile data in DB fresh (username/first_name/last_name)
dp.update.outer_middleware(ProfileSyncMiddleware())
dp.update.outer_middleware(
BanCheckMiddleware(settings=settings_param, i18n_instance=i18n_instance)
)