Skip to content

fix(storage): invalid storage details cache after writing operations - #2018

Open
hcrgm wants to merge 2 commits into
OpenListTeam:mainfrom
hcrgm:patch-2
Open

fix(storage): invalid storage details cache after writing operations#2018
hcrgm wants to merge 2 commits into
OpenListTeam:mainfrom
hcrgm:patch-2

Conversation

@hcrgm

@hcrgm hcrgm commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

Description / 描述

对存储驱动写操作成功后(上传、删除等),清除存储驱动的详情缓存,使容量数据更实时、准确。

Motivation and Context / 背景

发生上传、删除等写入操作后,容量信息没有发生变化,需要重新加载存储、根目录刷新或等缓存自然过期才发生变化。

How Has This Been Tested? / 测试

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it’s needed).
    我已相应更新了相关仓库(若适用)。

…enaming/copying/removing/puting

Signed-off-by: hcrgm <hcrgm@qq.com>
@hcrgm hcrgm changed the title fix(storage): invalid storage details cache after write operations fix(storage): invalid storage details cache after writing operations Jan 24, 2026
…an error

Signed-off-by: hcrgm <hcrgm@qq.com>
Comment thread internal/op/storage.go
details, err, _ := detailsG.Do(storage.GetStorage().MountPath, func() (*model.StorageDetails, error) {
ret, err := wd.GetDetails(ctx)
if err != nil {
Cache.InvalidateStorageDetails(storage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

此时Cache中还没有storage的容量信息,该语句产生的效果一定是什么也不做

Comment thread internal/op/fs.go
if storage.Config().NoCache {
return nil, nil
}
Cache.InvalidateStorageDetails(storage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

绝大多数情况下创建文件夹、移动、重命名都不会影响空间占用,不需要删除缓存

Comment thread internal/op/fs.go
Cache.linkCache.DeleteKey(stdpath.Join(dstKey, srcRawObj.GetName()))
}
if !storage.Config().NoCache {
Cache.InvalidateStorageDetails(storage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

同上

Comment thread internal/op/fs.go
Cache.linkCache.DeleteKey(stdpath.Join(dirKey, dstName))
}
if !storage.Config().NoCache {
Cache.InvalidateStorageDetails(storage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

同上

@pikachuren pikachuren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🙏 感谢 @hcrgm 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
⚠️ AI 分析结果仅供参考,可能存在误判或遗漏。如您发现任何问题或有不同意见,欢迎随时提出讨论和纠正。
⚠️ 重要提醒:即使 AI 评审认为代码质量良好且建议合并,最终是否合并仍需由项目维护者进行人工判定。项目维护者会综合考虑代码质量、项目规划、技术方向、团队资源等多方面因素做出决策。

🎯 结论

✅ 建议 Approve(由维护者人工确认)— 改动一致性好,仅需确认高频写入下的性能影响

📖 概要

fix(storage): invalid storage details cache after writing operations · 修复写操作后存储容量信息仍显示旧缓存的问题。
核心改动:在 MakeDir / Move / Rename / Copy / Remove / Put / PutURL 成功后调用 Cache.InvalidateStorageDetails,并在 GetDetails 失败时清理缓存。

🧭 整体方案

技术路线直接明了:所有会改变存储占用的写操作在成功后主动失效容量缓存,下次查询自然重新探测。改动点覆盖完整、位置一致(都在 !storage.Config().NoCache 保护内),方案合理。

📊 变更统计

2 个文件(+8 / -0 行) | 功能 ⭐⭐⭐⭐⭐ | 最小改动 ⭐⭐⭐⭐⭐ | 前向兼容 ⭐⭐⭐⭐⭐ | 方案设计 ⭐⭐⭐⭐

🚨 关键问题

P0(阻塞合并):无

P1(建议修复):无

P2(可选)

  • 💡 internal/op/fs.go — 批量场景(例如一次上传数百个文件)会对同一存储高频触发失效,导致后续每次查询都重新探测容量。对于探测代价高的网盘驱动(需要额外 API 调用),可能带来额外压力。是否考虑加一个轻量的合并窗口(例如失效后 N 秒内不重复探测)?不过这与 #2950 引入的 cooldown 机制存在重叠,建议两个 PR 的作者对齐一下~
  • 💡 internal/op/storage.go — 在 GetDetails 返回错误时调用 InvalidateStorageDetails,意味着一次网络抖动就会清掉本来还有效的旧数据,前端可能从「显示旧容量」退化为「显示 -」。是否考虑仅在明确的鉴权/存储失效类错误时才清缓存,普通网络错误保留旧值呢?
  • 💡 与 #2950internal/op/storage.go 同区域均有改动,合并时可能产生冲突,建议维护者留意先后顺序~

📂 逐文件分析

internal/op/fs.go

改动意图:写操作后让容量缓存失效。
代码逻辑:7 处写操作成功分支中统一插入 Cache.InvalidateStorageDetails(storage)
问题分析:插入位置一致且都在 NoCache 判断保护内,无遗漏;Remove 处放在 err == nil 内也正确。唯一可讨论的是高频写入下的探测放大(见 P2)。
详细建议:无需改动,若采纳合并窗口建议可与 #2950 统一实现。

internal/op/storage.go

改动意图:探测失败时不保留可能已失效的缓存。
问题分析:策略偏激进,建议区分错误类型(见 P2)。

✅ 待处理清单

  • [P2] 评估批量写入场景下的探测放大,考虑与 #2950 的 cooldown 机制对齐
  • [P2] 评估 GetDetails 失败时是否应保留旧缓存
  • [P2] 与 #2950 协调 internal/op/storage.go 的合并顺序

🎯 结论:✅ 建议 Approve — 覆盖完整、实现一致的合理修复,建议项均为可选优化。

@PIKACHUIM

Copy link
Copy Markdown
Member

建议修复P2问题后合并

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants