Skip to content

Comments

启动时清理解压缓存、缩短解压缓存哈希、Reader 跳转 Explorer 默认 table+按名排序#412

Open
hjyssg wants to merge 1 commit intonodejs-backendfrom
codex/optimize-service-startup-and-logs
Open

启动时清理解压缓存、缩短解压缓存哈希、Reader 跳转 Explorer 默认 table+按名排序#412
hjyssg wants to merge 1 commit intonodejs-backendfrom
codex/optimize-service-startup-and-logs

Conversation

@hjyssg
Copy link
Owner

@hjyssg hjyssg commented Feb 22, 2026

Motivation

  • 解决启动时复用旧解压缓存导致 Reader/Explorer 状态不一致的问题,同时在启动流程增加可见日志以便排查启动行为。
  • 后端缓存目录名过长,缩短哈希以便文件系统路径更可读且满足题主要求。
  • 从 Reader 打开 Explorer 时希望默认以表格(table)模式并按文件名排序,且能通过 URL 参数控制该模式。

Description

  • backendnode/src/server.ts 初始化 DB 后调用 clearExtractCache 做启动前的解压缓存清理,并打印清理结果与 activity log 写入状态。
  • backendnode/src/services/archiveService.tsgetExtractCacheDir 改为仅使用 sha256 前 10 位(保留二级目录切分 2+8)。
  • 前端导出 FileViewContainerViewMode 类型并在 frontend/src/routes/_layout/explorer.tsx 中增加对可选 viewMode 查询参数的解析、验证与透传,且在分页/排序/面包屑跳转时保留该参数。
  • frontend/src/routes/_layout/read.tsx 中多个从 Reader 跳转到 Explorer 的入口统一改为 viewMode=table, sortField=name, sortOrder=asc,并在无图/音频模式等处同步使用该默认参数。

Testing

  • 运行 npm run -C backendnode buildtsc)时被仓库已有的类型测试错误阻断,错误与本次改动无关(若干测试使用了未在类型中声明的字段如 fingerprint)。
  • 运行 npm run -C frontend build 时 TypeScript 编译通过但 Vite 打包阶段因环境缺失可选原生依赖 @rollup/rollup-linux-x64-gnu 而失败,TS 部分的改动已通过本地类型检查。
  • 已将修改提交并生成 PR(包含涉及文件清单)。

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27b27b2653

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const hash = crypto.createHash("sha256").update(archivePath).digest("hex");
const base = path.resolve(config.EXTRACT_CACHE_DIR);
return path.join(base, hash.slice(0, 2), hash.slice(2));
const shortHash = hash.slice(0, 10);

Choose a reason for hiding this comment

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

P1 Badge Restore sufficiently unique extract cache keys

Using only hash.slice(0, 10) reduces the cache key to 40 bits, so different archive paths can map to the same extraction directory once libraries get moderately large. Because extraction/read paths are keyed only by getExtractCacheDir(archivePath) (no archive identity check in the cache directory), a collision will cause cross-archive cache reuse (wrong files shown, stale reads, and accidental overwrite of another archive’s extracted files).

Useful? React with 👍 / 👎.

isLoading={isLoading}
currentPath={path}
initialViewMode="mixed"
initialViewMode={viewMode ?? "mixed"}

Choose a reason for hiding this comment

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

P2 Badge Honor viewMode URL override instead of stored preference

Passing viewMode via initialViewMode does not reliably enforce the requested mode, because FileViewContainer initializes view mode from localStorage first and only falls back to initialViewMode. In practice, users with an existing explorer-view-mode value (for example grid) will still land in that saved mode even when links now set viewMode=table, so the new Reader→Explorer default is silently ignored for those users.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant