qiniu / qiniu/coding-helper

perf: 避免工具更新后重复查询 npm 最新版本

Open
#24 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3
Forks
1
Avg merge
5h 2m
Merged PRs (30d)
1

Description

背景

PR #23 的 review 中指出,工具菜单执行更新流程时存在重复查询 npm registry 最新版本的情况。

当前流程大致是:

  1. showToolMenu 在用户选择「更新工具」后调用 updateTool(tool)
  2. updateTool(tool) 内部会调用 fetchLatestVersion(tool.npmPackageName),用于判断是否需要更新和展示确认信息。
  3. updateTool(tool) 返回后,showToolMenu 又重新调用一次 fetchLatestVersion(tool.npmPackageName) 来刷新菜单中的最新版本状态。

这不会影响正确性,但在 npm registry 网络较慢、不可达或受代理影响时,会造成额外等待和网络开销。

目标

优化工具更新后的版本信息刷新逻辑,避免同一次更新动作中重复查询 npm registry。

可能方案

  • updateTool(tool) 返回本次查询到的 latest version,供外层菜单复用。
  • 或抽出统一的版本查询/刷新函数,让更新流程和菜单刷新共享结果。
  • 保持当前行为语义:更新前仍能判断是否已是最新版本,更新后菜单仍能显示合理的最新版本状态。

验收标准

  • 用户选择「更新工具」时,不再因为菜单和 updateTool 各自查询而重复请求 npm registry。
  • npm registry 查询失败时,菜单不会进入 abort 重渲染循环。
  • 保留或补充对应测试,覆盖更新后版本状态刷新逻辑。

来源

来自 PR #23 的 review 建议。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the showToolMenu, updateTool, and fetchLatestVersion entry points to trace the current version queries. Locate the existing tests for the update and menu flow, then verify that one update action reuses the fetched version, avoids abort re-rendering on registry failure, and preserves the displayed version state.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.