Skip to content

Commit 23de537

Browse files
committed
fix: moved function
1 parent 2ebb919 commit 23de537

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

userbot/db/db_manager.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import logging
33
from datetime import datetime, timezone, timedelta
4-
from pathlib import Path
54
from typing import Optional, Any, List, Dict
65

76
from sqlalchemy import select, update, delete, asc, desc
@@ -149,6 +148,23 @@ async def get_active_modules_for_account(db: AsyncSession, account_id: int) -> L
149148
return result.scalars().all()
150149

151150
# --- Log Management ---
151+
async def add_logs_bulk(db: AsyncSession, logs: List[Dict[str, Any]]) -> None:
152+
"""
153+
Adds a batch of log entries to the database.
154+
155+
Args:
156+
db (AsyncSession): The database session.
157+
logs (List[Dict[str, Any]]): A list of dictionaries, where each
158+
dictionary represents a log entry.
159+
"""
160+
if not logs: return
161+
try:
162+
db.add_all([Log(**log_data) for log_data in logs])
163+
await db.flush()
164+
except Exception as e:
165+
# Fallback to console print if DB fails, to avoid losing logs entirely.
166+
print(f"CRITICAL: Error during bulk log insert: {e}")
167+
152168
async def get_logs_advanced(db: AsyncSession, mode: str, limit: int, level: Optional[str] = None, source: Optional[str] = None) -> List[Log]:
153169
stmt = select(Log)
154170
if level: stmt = stmt.where(Log.level == level.upper())

0 commit comments

Comments
 (0)