Repository navigation
perf(database): enable WAL and cache proxy hot-path reads - #9820
Merged
farion1231 merged 1 commit intoNov 23, 2026
Merged
Conversation
4 tasks done
funkpopo
previously approved these changes
Nov 21, 2026
funkpopo
left a comment
Collaborator
There was a problem hiding this comment.
整体设计与边界保护非常严谨,针对主库热路径的 WAL 模式、连接缓存、代数戳记读缓存与异步 offload 都处理得很到位。
审查要点确认
- WAL 与生命周期一致性 (
src-tauri/src/database/mod.rs#L181-L219):统一启用WAL、synchronous = NORMAL、5 秒busy_timeout与 16 MiB 页缓存,并在退出与重启路径补全PRAGMA wal_checkpoint(TRUNCATE);run_blocking也兼容了 Tokio 运行时尚未就绪时的启动回退。 - 读缓存及无死角失效 (
src-tauri/src/database/mod.rs#L133-L163、src-tauri/src/database/read_cache.rs#L73-L84):ProxyReadCache绑定mutation_generation防并发陈旧回填,不缓存错误结果,并刻意保持本地设备路由文件不缓存;通过update_hook+rollback_hook失效缓存,对缓存表的DELETE由 authorizer 返回Authorization::Ignore(保留DROP TABLE豁免)以确保整表删除也能逐行触发失效;replace_from_staging在在线备份前校验/对齐page_size并重新配置连接与失效读缓存。 - 协调提示(非阻塞):如果正在评审中的
database/backup.rs测试拆分(#9806)先于本 PR 合并,后续 rebase 时需将本 PR 新增的 WAL 导入恢复测试同步落到database/backup/tests.rs。 - 验证结果:在
mainmerge-tree 上本地实测通过cargo fmt --check、cargo clippy -- -D warnings(--all-targets无新增告警),以及read_cache::tests、wal_import_and_restore_keep_pragmas_and_invalidate_cached_reads、providers::tests、ensure_incremental_auto_vacuum、proxy_dao_calls_survive_a_poisoned_lock和response_processor::tests;四平台 GitHub CI 全部通过,予以批准。
YUZHEthefool
force-pushed
the
perf/database-proxy-cache
branch
from
November 23, 2026 03:30
edd7918 to
d5888b1
Compare
This was referenced Nov 23, 2026
Owner
|
已合并,感谢 @YUZHEthefool!这一批性能 PR(#9817、#9818、#9820)叠在最新 main 上一起验证过,fmt / clippy / 全部测试都通过,会随下一版发布。 |
Liam-Frost
added a commit
to Liam-Frost/cc-switch
that referenced
this pull request
Nov 23, 2026
Adapt Claude Desktop to upstream's proxy hot-path cache (farion1231#9820) and the ForwardBody request type (farion1231#9821): - Claude Desktop's app-level config lives in the settings table, but the new proxy_config and pricing-source caches only invalidate on proxy_config writes. Keep Desktop out of those caches and read it through the settings cache instead, adding its two keys to the cached settings so warm Desktop requests do not wait for the database mutex. - The usage logger now calls the sync pricing-source read; the Desktop fallback to Claude stays in the DAO. - The unmapped-provider skip reads the model from ForwardBody::model() instead of the request body, so it does not parse or copy the body. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Human Note / 本人说明
perf:重构数据库,网络链接,减少额外性能开销
Summary / 概述
主库使用默认回滚日志和 FULL 同步,每次代理请求还会重复读取配置、路由和定价;多个标记为 async 的代理 DAO 直接等待全局 SQLite 互斥锁,阻塞 Tokio worker。
synchronous=NORMAL、5 秒忙等待、内存临时表和约 16 MiB 页缓存;退出及重启清理增加 WAL checkpoint。复核更正:锁定的 rusqlite 版本已默认设置 5 秒忙等待,本次将其显式化。锁次数取决于请求路径和缓存冷热,没有声称固定的吞吐提升。设备路由状态仍读取最新文件,避免缓存过时路由。
NORMAL按本次要求减少提交时的同步开销;与 FULL 相比,系统崩溃或断电时最近提交的持久性较弱。Related Issue / 关联 Issue
本次性能复核的第 2 项:主库写入同步与代理请求重复争用数据库锁。暂无独立 Issue。
Screenshots / 截图
不适用,后端数据库与代理执行路径调整。
Validation / 验证
cargo fmt --check、git diff --check、cargo clippy --locked --offline --manifest-path src-tauri/Cargo.toml -- -D warnings通过。本机通过
OPENSSL_DIR使用已有 OpenSSL 3 头文件和库以匹配锁定依赖,未改动 Cargo 依赖。bun run typecheck、bun run format:check通过;它们执行与 pnpm 同名的 package.json 脚本,四个分支的前端代码相同。Checklist / 检查清单
pnpm typecheckpasses / 通过 TypeScript 类型检查(本机使用bun run typecheck)pnpm format:checkpasses / 通过代码格式检查(本机使用bun run format:check)cargo clippypasses (if Rust code changed) / 通过 Clippy 检查(启用-D warnings)