Repository navigation
效能與併發:同步磁碟 I/O 移出主 isolate、資料庫 WAL、索引、桌面音訊懶載入 - #486
Merged
Merged
Conversation
Carinoasd
changed the base branch from
chore/claude-md-housekeeping
to
master
November 27, 2026 08:08
Carinoasd
force-pushed
the
perf/io-db-wal
branch
from
November 27, 2026 08:09
f8b4625 to
ca08937
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
疊在 #485 上(base 是
chore/claude-md-housekeeping)。不改 UI,不動packages/。1. 主 isolate 上的同步磁碟 I/O
image_cache_provider.dart):calculateCache()、clearCache()、clearEmojiCache()的列目錄、stat、刪除改在Isolate.run裡做,和同檔的trimCache同一種寫法(image_cache_trim.dart新增directorySizeOf、emptyDirectory)。getEmojiCacheSync()加一個 8 MB 上限的記憶體 LRU。每個表情只讀一次磁碟,之後開面板、切分頁都從記憶體拿。重新下載(updateEmojiCache)與清除快取會讓對應項目失效。instance.dart):7 天前舊日誌的清理移到deleteOldLogs,用非同步的list()/stat(),initLogger()不等它。2. SQLite
connection/native.dart的setupConnection):busy_timeout = 5000(保留,放最前面)→journal_mode = WAL→synchronous = NORMAL。切換模式失敗(另一個 isolate 正以舊模式開著)時維持原狀,下次啟動再切。backup_repository.dart):VACUUM前設journal_mode = DELETE,備份檔一律是單一檔案;收尾清掉副本的-wal/-shm/-journal。匯出走另一條連線讀,還在-wal裡的寫入也會進備份。.bak前先對現有資料庫wal_checkpoint(TRUNCATE),否則只在-wal裡的最後寫入不會進.bak,還原失敗回滾時會遺失;換檔前刪掉舊資料庫的旁檔。_restore):把.bak放回去之前先刪掉失敗那份的旁檔,避免舊的-wal被套到還原的檔案上。deleteLeftovers:匯入/匯出副本與.bak的-wal/-shm/-journal一起清,資料庫本身的旁檔不碰。image_cache (last_used_time)、notice (uid, timestamp)、personal_message (uid, timestamp)、thread_visit_history (uid, visit_time)。遷移逐一檢查,缺的才建,另一條連線剛建好就略過。broadcast_message (uid, timestamp)沒有加:這張表的主鍵就是(uid, timestamp),SQLite 已有同樣的自動索引,測試用EXPLAIN QUERY PLAN確認查詢走它且不需排序。3. 冷啟動的音訊初始化
JustAudioMediaKit.ensureInitialized()移到ensureDesktopAudioPlayer(),由JustAudioBackend在建立第一個AudioPlayer前呼叫。JustAudioBackground.init維持在runApp之前。套件要求在main()裡初始化一次;Android 上媒體鍵或系統重新叫起音訊服務時,引擎是在沒有 activity、也沒有任何播放動作的情況下啟動的,延後到首次播放會讓服務沒有 handler。原因寫在initAudioPlayer的註解裡。驗證
dart ./scripts/check_strict_analyzing.dart:No issues found。test_1424_wal_and_sync_io_test.dart(14 個):連線設定、WAL 下讀寫不互擋、匯出/匯入/回滾/無效來源都不留旁檔、回滾後最後寫入還在、索引的查詢計畫、目錄大小與清空、舊日誌清理、表情 LRU。暫時拿掉換檔前的 checkpoint,回滾那一條會失敗。test_002_database_migration_test.dart:補 20 → 21、重跑安全、從 10/15/19 一次升到 21。🤖 Generated with Claude Code