Refactor metrics handling and remove scheduler
- Removed the metrics scheduler functionality from the bot, transitioning to real-time metrics updates via middleware. - Enhanced logging for metrics operations across various handlers to improve monitoring and debugging capabilities. - Integrated metrics tracking for user activities and database errors, providing better insights into bot performance. - Cleaned up code by removing obsolete comments and unused imports, improving overall readability and maintainability.
This commit is contained in:
@@ -162,7 +162,7 @@ class MetricsMiddleware(BaseMiddleware):
|
||||
await bot_db.cursor.execute(total_users_query)
|
||||
total_users_result = await bot_db.cursor.fetchone()
|
||||
total_users = total_users_result[0] if total_users_result else 1
|
||||
daily_users_query = "SELECT COUNT(DISTINCT user_id) as active_users FROM our_users WHERE date_changed > datetime('now', '-1 day'))"
|
||||
daily_users_query = "SELECT COUNT(DISTINCT user_id) as active_users FROM our_users WHERE date_changed > datetime('now', '-1 day')"
|
||||
await bot_db.cursor.execute(daily_users_query)
|
||||
daily_users_result = await bot_db.cursor.fetchone()
|
||||
daily_users = daily_users_result[0] if daily_users_result else 1
|
||||
@@ -328,8 +328,21 @@ class MetricsMiddleware(BaseMiddleware):
|
||||
|
||||
# FALLBACK: Record unknown callback
|
||||
if parts:
|
||||
callback_data = parts[0]
|
||||
|
||||
# Группируем похожие callback'и по паттернам
|
||||
if callback_data.startswith("ban_") and callback_data[4:].isdigit():
|
||||
# callback_ban_123456 -> callback_ban
|
||||
command = "callback_ban"
|
||||
elif callback_data.startswith("page_") and callback_data[5:].isdigit():
|
||||
# callback_page_2 -> callback_page
|
||||
command = "callback_page"
|
||||
else:
|
||||
# Для остальных неизвестных callback'ов оставляем как есть
|
||||
command = f"callback_{callback_data[:20]}"
|
||||
|
||||
return {
|
||||
'command': f"callback_{parts[0][:20]}",
|
||||
'command': command,
|
||||
'user_type': "user" if callback.from_user else "unknown",
|
||||
'handler_type': "unknown_callback_handler"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user