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

Abierto
#476 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@fx-kurumi ya está trabajando en esto.

Desde el 13/11/2026.

  • #477 de @fx-kurumi — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
25/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
go
Área
api, backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

现状问题

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/ 相关用例通过。
Lenguaje dominante
Go
Estrellas
141
Forks
28
Merge medio
1 d 15 h
PR fusionados (30 d)
113

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Tencent/LoopForge

Todos los issues de Tencent/LoopForge

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.