fix: add WAL mode for session SQLite to prevent 'database is locked', persist active account tab in localStorage

This commit is contained in:
2026-06-27 15:45:05 +02:00
parent 93f2b94dd2
commit 1bd385e054
3 changed files with 20 additions and 2 deletions
+14
View File
@@ -79,6 +79,19 @@ class ForwardingRule:
enabled: bool = True
def _ensure_session_wal(session_path: str) -> None:
db_path = session_path if session_path.endswith(".session") else f"{session_path}.session"
if not Path(db_path).exists():
return
try:
conn = sqlite3.connect(db_path, timeout=1)
conn.execute("PRAGMA journal_mode=WAL;")
conn.execute("PRAGMA synchronous=NORMAL;")
conn.close()
except Exception:
pass
class OptimizedTelegramScraper:
def __init__(self, account_id: Optional[str] = None):
self.account_id = account_id
@@ -1496,6 +1509,7 @@ class OptimizedTelegramScraper:
return False
session = account_session_path(self.SESSION_DIR, self.account_id or "session")
_ensure_session_wal(session)
self.client = TelegramClient(
session,
self.state["api_id"],