Repository navigation
删除消息时,一并删除不再被引用的图片缓存 - #368
Merged
Merged
Conversation
Owner
|
哈喽,之前比较忙没时间 review,我刚看了下,大致逻辑是我想要的。 |
Fiiiga
force-pushed
the
fix/delete-message-image-cache
branch
from
September 26, 2026 04:34
8bb6906 to
f6f8eb3
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
存在跨进程引用竞态、后台任务可能未完成,以及使用过期 UI 图片地址的问题。
Review effort: Balanced
Findings: 3
Open (3)
异步缓存清理未完成即结束后台任务,可能遗留磁盘缓存 · New 清理缓存未考虑待处理通知,可能删除扩展正在使用的附件 · New 使用过期 UI 图片地址清理缓存,可能遗漏当前图片 · New
What changed in this PR
新增消息图片缓存清理机制,在删除消息后移除无引用的 Kingfisher 缓存。
Changes:
- 为图片字段建立索引并升级 Realm schema。
- 新增后台引用检查与缓存清理器。
- 接入单条、分组、批量、远程及过期删除路径。
| File | Description |
|---|---|
Model/Message.swift |
为图片地址添加 Realm 索引 |
Common/RealmConfiguration.swift |
升级 schema 版本 |
Common/MessageImageCleaner.swift |
实现无引用图片清理 |
Controller/MessageListViewModel.swift |
接入列表删除流程 |
Bark/AppDelegate+Realm.swift |
清理过期消息图片 |
Bark/AppDelegate.swift |
接入远程删除流程 |
Bark.xcodeproj/project.pbxproj |
将清理器加入应用目标 |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.

问题
目前所有删除路径都只删了数据库记录,图片文件无法被清理,也不会自动过期。
导致即使用户清空全部历史记录,图片占用的空间也不会释放,只能重装解决。
改动
新增 MessageImageCleaner,删除消息时一并清理不再被引用的图片缓存。
因同一个图片地址可能被多条消息引用,所以做了引用检查。清理跑在后台队列上。
接入了 6 个删除点:列表左滑单条、左滑分组、分组清空按钮、actionSheet 删除、右上角垃圾桶批量删除,以及 delete=1 远程删除和 ttl 过期自动删除。
需要确认的取舍
下拉查看大图会重新联网下载。NotificationContentExtension 读的是同一份缓存,缓存删掉后会重新下载。(通知中心里推送的缩略图是 NSE 复制的附件副本,不受影响)。不确定是否符合预期。
后两个删除点(远程删除、ttl 过期)是否该包含在内?它们不是用户主动点删除,但同样是消息永久消失。如果觉得不合适可以拆掉。
没有加测试。
说明
代码跑了 CI 验证,但时间仓促未本地编译。