Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create sync task by 'GET /:fullname/-/:filenameWithVersion.tgz' #526

Merged
merged 6 commits into from
Jun 21, 2023

Conversation

hezhengxu2018
Copy link
Collaborator

@hezhengxu2018 hezhengxu2018 commented Jun 19, 2023

used by pnpm project with lock

closes #525

const packageVersion = await this.packageRepository.findPackageVersion(pkg.packageId, version);
if (!packageVersion) {
throw this.createPackageNotFoundErrorWithRedirect(pkg.fullname, version);
throw this.createPackageNotFoundErrorWithRedirect(pkg.fullname, version, allowSync);
}
return packageVersion;
}

Choose a reason for hiding this comment

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

这段代码通过增加一个新的可选参数 allowSync 来改进三个方法:getPackageEntityByFullname, getPackageEntitygetPackageVersionEntity. 这个参数允许控制数据库中检索实体时,是否可以跨过异步执行任务(例如基于 Promise 的查询)来同步获取数据. 在代码变更的详细实现方式看不到前面的某些代码。因此无法评价可能存在的任何其他风险或限制。

const packageVersion = await this.getPackageVersionEntity(pkg, version);
const allowSync = this.getAllowSync(ctx);
const pkg = await this.getPackageEntityByFullname(fullname, allowSync);
const packageVersion = await this.getPackageVersionEntity(pkg, version, allowSync);

// read by nfs url
if (downloadUrl) {

Choose a reason for hiding this comment

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

这段代码可以进行如下改进:

1.注释修改:代码中的一些注释需要更改。特别是“// try nfs url first, avoid db query”和“// read by nfs url”的注释可能与实际情况不符。

2.异常处理:代码中没有异常处理机制,建议添加适当的异常处理机制。

3.代码可读性提高:代码中存在一些重复的方法调用,建议使用变量来存储结果。还建议在命名参数时使用有意义的名称。

4.潜在 bug 风险:下载 URL 可能会返回一个空字符串,这可能导致问题。建议添加一个检查以防止返回空字符串时出现问题。

@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #526 (7828dc9) into master (eb91b83) will decrease coverage by 0.03%.
The diff coverage is 70.58%.

@@            Coverage Diff             @@
##           master     #526      +/-   ##
==========================================
- Coverage   97.00%   96.97%   -0.03%     
==========================================
  Files         174      174              
  Lines       16538    16546       +8     
  Branches     2162     2167       +5     
==========================================
+ Hits        16043    16046       +3     
- Misses        495      500       +5     
Impacted Files Coverage Δ
...rt/controller/package/DownloadPackageVersionTar.ts 90.12% <54.54%> (-5.77%) ⬇️
app/port/controller/AbstractController.ts 98.95% <100.00%> (ø)

@fengmk2 fengmk2 added the bug Something isn't working label Jun 19, 2023
@fengmk2
Copy link
Member

fengmk2 commented Jun 19, 2023

@hezhengxu2018 补充一个对应的单测

@fengmk2 fengmk2 self-assigned this Jun 20, 2023
@hezhengxu2018 hezhengxu2018 marked this pull request as draft June 20, 2023 01:19
@hezhengxu2018 hezhengxu2018 marked this pull request as ready for review June 20, 2023 12:27
@fengmk2
Copy link
Member

fengmk2 commented Jun 20, 2023

rebase 一下?带了已经合并的代码。

const packageVersion = await this.getPackageVersionEntity(pkg, version);
const allowSync = this.getAllowSync(ctx);
const pkg = await this.getPackageEntityByFullname(fullname, allowSync);
const packageVersion = await this.getPackageVersionEntity(pkg, version, allowSync);

// read by nfs url
if (downloadUrl) {

Choose a reason for hiding this comment

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

这段代码需要下载软件包。以下是我对该代码的审查:

1.15行的'getPackageEntityByFullname'和28行的'getPackageVersionEntity'在哪里定义?是否存在将被调用的类型定义文件?如果没有,建议添加类型定义。

2.引入allowSync变量的设计和使用方式不清楚。建议提供有关其作用和目的的注释。

3.建议添加错误处理和恢复机制,以保证稳健性。

4.建议考虑支持其他协议(例如HTTP)中的URL下载。

5.42行建议更改为异步调用以优化性能

在上述东西得到满足之前不能确认缺陷和修复建议。

@hezhengxu2018
Copy link
Collaborator Author

好了

Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

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

+1

@fengmk2 fengmk2 merged commit 5ceaa6b into master Jun 21, 2023
11 of 13 checks passed
@fengmk2 fengmk2 deleted the fix-allow-sync branch June 21, 2023 00:46
fengmk2 pushed a commit that referenced this pull request Jun 21, 2023
[skip ci]

## [3.34.5](v3.34.4...v3.34.5) (2023-06-21)

### Bug Fixes

* create sync task by 'GET /:fullname/-/:filenameWithVersion.tgz' ([#526](#526)) ([5ceaa6b](5ceaa6b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用SyncMode.exist模式
3 participants