Skip to content

删除消息时,一并删除不再被引用的图片缓存 - #368

Merged
Finb merged 3 commits into
Finb:masterfrom
Fiiiga:fix/delete-message-image-cache
Sep 30, 2026
Merged

Finb merged 3 commits into
Finb:masterfrom
Fiiiga:fix/delete-message-image-cache

Conversation

@Fiiiga

@Fiiiga Fiiiga commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

问题

目前所有删除路径都只删了数据库记录,图片文件无法被清理,也不会自动过期。
导致即使用户清空全部历史记录,图片占用的空间也不会释放,只能重装解决。

改动

新增 MessageImageCleaner,删除消息时一并清理不再被引用的图片缓存。

因同一个图片地址可能被多条消息引用,所以做了引用检查。清理跑在后台队列上。

接入了 6 个删除点:列表左滑单条、左滑分组、分组清空按钮、actionSheet 删除、右上角垃圾桶批量删除,以及 delete=1 远程删除和 ttl 过期自动删除。

需要确认的取舍

  1. 下拉查看大图会重新联网下载。NotificationContentExtension 读的是同一份缓存,缓存删掉后会重新下载。(通知中心里推送的缩略图是 NSE 复制的附件副本,不受影响)。不确定是否符合预期。

  2. 后两个删除点(远程删除、ttl 过期)是否该包含在内?它们不是用户主动点删除,但同样是消息永久消失。如果觉得不合适可以拆掉。

  3. 没有加测试。

说明

代码跑了 CI 验证,但时间仓促未本地编译。

@Finb

Finb commented Sep 22, 2026

Copy link
Copy Markdown
Owner

哈喽,之前比较忙没时间 review,我刚看了下,大致逻辑是我想要的。
但实现方式我想 查询关联 image 时加数据库索引来查询,而不是全表查询过滤。

@Fiiiga
Fiiiga force-pushed the fix/delete-message-image-cache branch from 8bb6906 to f6f8eb3 Compare September 26, 2026 04:34
@Finb
Finb requested a balanced review from Copilot September 28, 2026 02:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

存在跨进程引用竞态、后台任务可能未完成,以及使用过期 UI 图片地址的问题。

Review effort: Balanced
Findings: 3 Medium severity

Open (3)
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.

Comment thread Bark/AppDelegate.swift Outdated
Comment thread Common/MessageImageCleaner.swift
Comment thread Controller/MessageListViewModel.swift
@Finb
Finb merged commit 1f3da9a into Finb:master Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants