【架构优化】从 recentDeckPathsIn 中拆出临时目录扫描 tempDirDeckFiles 与时间窗口过滤 filterRecentRegularFiles

未關閉
#476 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@fx-kurumi 已經在處理了。

開始於 2026年11月13日。

  • #477 來自 @fx-kurumi —— 未關閉

評估

難度
3/5
預估耗時
半天
新手友好度
25/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
go
領域
api, backend

研究方向

Start in internal/httpapi/assistant_workbench.go at recentDeckPathsIn, which mixes workspace collection, the os.TempDir() scan with its early return uniquePaths(out), and the time-window filter. The proposed split is tempDirDeckFiles and filterRecentRegularFiles, and the existing read-failure branch must keep its current behaviour. Done means new unit tests for both helpers pass alongside go test ./internal/httpapi/. Pull request #477 is already open against this issue, so check it before starting any work.

由索引模型根據 Issue 內容生成。

描述

现状问题

internal/httpapi/assistant_workbench.go 中的 recentDeckPathsIn 约 40 行,同时做了三件事:

  1. 收集工作区 ws/、home/tmp/ 下的 pptx;
  2. 扫描系统临时目录(os.TempDir())下的 pptx 文件,以及名字含 ppt/slide/loopforge 的子目录;
  3. 去重后按修改时间窗口(since-30s ~ until)过滤出“新生成”的文件。

其中临时目录扫描分支还带有一个提前 return uniquePaths(out) 的出口,让读者需要来回比对两个返回路径;时间窗口过滤也无法单独测试。

重构方案

  • 拆出 tempDirDeckFiles() ([]string, error):只负责扫描系统临时目录,读目录失败返回错误;
  • 拆出 filterRecentRegularFiles(paths []string, since, until time.Time) []string:只负责“常规文件 + 时间窗口”过滤;
  • recentDeckPathsIn 只做组合:收集候选 → uniquePaths → 时间过滤。

影响范围

仅 internal/httpapi/assistant_workbench.go 内部未导出函数,对外接口与行为不变。
注意:原实现在读临时目录失败时直接返回去重后的候选而不做时间过滤;为了保证行为严格不变,重构后保留这一分支语义。

验证方式

  • 新增单元测试覆盖 filterRecentRegularFiles(窗口内外、非常规文件、零值边界)与 tempDirDeckFiles(目录名过滤、顶层 pptx);
  • gofmt、go vet ./internal/httpapi/、go test ./internal/httpapi/ 相关用例通过。
主要語言
Go
星號
141
分支
28
平均合併
1 天 15 小時
30 天內合併 PR
113

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Tencent/LoopForge 的其他 Issue

查看 Tencent/LoopForge 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。