|
1 | | -"""Background auto-sync from WCDB realtime (db_storage) into decrypted sqlite. |
| 1 | +"""Optional background auto-sync from WCDB realtime (db_storage) into decrypted sqlite. |
2 | 2 |
|
3 | 3 | Why: |
4 | | -- The UI can read "latest" messages from WCDB realtime (`source=realtime`), but most APIs default to the |
5 | | - decrypted sqlite snapshot (`source=decrypted`). |
6 | | -- Previously we only synced realtime -> decrypted when the UI toggled realtime off, which caused `/api/chat/messages` |
7 | | - to lag behind while realtime was enabled. |
| 4 | +- The chat UI now defaults to reading from WCDB realtime (`source=auto`), so it does not need a second |
| 5 | + always-updated decrypted copy for display. |
| 6 | +- This service is kept as an opt-in compatibility bridge for workflows that still require the decrypted |
| 7 | + sqlite snapshot to be incrementally updated. |
8 | 8 |
|
9 | 9 | This module runs a lightweight background poller that watches db_storage mtime changes and triggers an incremental |
10 | 10 | sync_all into decrypted sqlite. It is intentionally conservative (debounced + rate-limited) to avoid hammering the |
@@ -105,7 +105,7 @@ class _AccountState: |
105 | 105 |
|
106 | 106 | class ChatRealtimeAutoSyncService: |
107 | 107 | def __init__(self) -> None: |
108 | | - self._enabled = _env_bool("WECHAT_TOOL_REALTIME_AUTOSYNC", True) |
| 108 | + self._enabled = _env_bool("WECHAT_TOOL_REALTIME_AUTOSYNC", False) |
109 | 109 | self._interval_ms = _env_int("WECHAT_TOOL_REALTIME_AUTOSYNC_INTERVAL_MS", 1000, min_v=200, max_v=10_000) |
110 | 110 | self._debounce_ms = _env_int("WECHAT_TOOL_REALTIME_AUTOSYNC_DEBOUNCE_MS", 600, min_v=0, max_v=10_000) |
111 | 111 | self._min_sync_interval_ms = _env_int( |
@@ -181,7 +181,7 @@ def resume_account(self, account: str, reason: str = "") -> int: |
181 | 181 |
|
182 | 182 | def start(self) -> None: |
183 | 183 | if not self._enabled: |
184 | | - logger.info("[realtime-autosync] disabled by env WECHAT_TOOL_REALTIME_AUTOSYNC=0") |
| 184 | + logger.info("[realtime-autosync] disabled (set WECHAT_TOOL_REALTIME_AUTOSYNC=1 to enable)") |
185 | 185 | return |
186 | 186 |
|
187 | 187 | with self._mu: |
|
0 commit comments