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

feat: impl fast semver search #495

Merged
merged 2 commits into from
Jun 6, 2023
Merged

feat: impl fast semver search #495

merged 2 commits into from
Jun 6, 2023

Conversation

killagu
Copy link
Contributor

@killagu killagu commented Jun 6, 2023

Including SQL change.

close #134

@killagu killagu force-pushed the feat/fast_semver branch from 9143e25 to 91ee7af Compare June 6, 2023 05:03
@socket-security
Copy link

New and updated dependency changes detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives1 Size Publisher
npm-package-arg 🆕 10.1.0 environment +4 63.1 kB gar

Footnotes

  1. https://docs.socket.dev

private readonly bugVersionStore: BugVersionStore;

async getBugVersion(): Promise<BugVersion | undefined> {
// TODO performance problem, cache bugVersion and update with schedule
Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里可能是一个热点,如果上线后实际存在需要额外增加缓存。

Copy link
Member

@fengmk2 fengmk2 Jun 6, 2023

Choose a reason for hiding this comment

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

先加一个进程 LRU?缓存一下1分钟,性能应该就不是问题了。

@Inject()
private readonly logger: EggLogger;

async fixPaddingVersion(id?: number): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

需要在业务低峰阶段调用此方法来订正数据,此方法会造成单进程 CPU 持续打满。

}
let manifest;
if (isFullManifests) {
manifest = await this.distRepository.findPackageVersionManifest(pkgId, version);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

存在一次额外的数据库访问,可以直接用过 fullname + version 的方式拼接出 nfs key。

@killagu killagu force-pushed the feat/fast_semver branch from 26d78ae to 62cf2ca Compare June 6, 2023 05:13
@killagu
Copy link
Contributor Author

killagu commented Jun 6, 2023

#134
#452

@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Merging #495 (26d78ae) into master (6624a36) will decrease coverage by 0.27%.
The diff coverage is 90.11%.

❗ Current head 26d78ae differs from pull request most recent head 4d0815b. Consider uploading reports for the commit 4d0815b to get more accurate results

@@            Coverage Diff             @@
##           master     #495      +/-   ##
==========================================
- Coverage   97.45%   97.18%   -0.27%     
==========================================
  Files         168      174       +6     
  Lines       15691    16182     +491     
  Branches     2018     2078      +60     
==========================================
+ Hits        15291    15727     +436     
- Misses        400      455      +55     
Impacted Files Coverage Δ
.../port/controller/admin/PaddingVersionController.ts 48.83% <48.83%> (ø)
app/core/service/FixNoPaddingVersionService.ts 54.54% <54.54%> (ø)
app/repository/PackageVersionRepository.ts 87.95% <87.95%> (ø)
app/core/service/BugVersionService.ts 91.08% <91.66%> (+0.06%) ⬆️
app/core/service/PackageVersionService.ts 94.95% <94.95%> (ø)
app/core/entity/PaddingSemVer.ts 95.55% <95.55%> (ø)
app/core/entity/SqlRange.ts 97.53% <97.53%> (ø)
app/core/service/PackageManagerService.ts 98.93% <97.77%> (-0.02%) ⬇️
app/core/entity/PackageVersion.ts 100.00% <100.00%> (ø)
app/core/entity/Token.ts 100.00% <100.00%> (ø)
... and 15 more

... and 1 file with indirect coverage changes

@fengmk2 fengmk2 added the enhancement New feature or request label Jun 6, 2023
This was linked to issues Jun 6, 2023
@killagu killagu force-pushed the feat/fast_semver branch from 62cf2ca to bd51659 Compare June 6, 2023 05:44
sql/3.24.0.sql Outdated Show resolved Hide resolved
@fengmk2 fengmk2 added the sql include sql change label Jun 6, 2023
$and: [
{
isPreRelease: {
$lte: 0,
Copy link
Member

Choose a reason for hiding this comment

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

$eq 0 性能会不会更好些?

@Attribute(DataTypes.BOOLEAN)
isPreRelease: boolean;

static beforeCreate(instance) {
Copy link
Member

Choose a reason for hiding this comment

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

学习了。

ADD
COLUMN `is_pre_release` tinyint(4) DEFAULT NULL COMMENT '是否是先行版本',
ADD
KEY `idx_pkg_id_is_pre_release_padding_version` (`package_id`, `padding_version`, `is_pre_release`, `version`);
Copy link
Member

Choose a reason for hiding this comment

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

索引为什么会加上 version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这样可以直接利用索引数据,避免回表,通过 explain sql 可以看到 using index 是最佳的效果。

}
return { manifest, blockReason, pkg };
const fullname = getFullname(scope, name);
const result = npa(`${fullname}@${spec}`);
Copy link
Member

Choose a reason for hiding this comment

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

希望未来 npa 不会成为性能瓶颈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个开销比较大的,好在前面有 cdn 缓存,不会高频使用。

@@ -107,7 +107,7 @@ export class PackageVersionFileController extends AbstractController {
}
return files;
}
const { manifest } = await this.packageManagerService.showPackageVersionManifest(scope, name, versionOrTag);
const { manifest } = await this.packageManagerService.showPackageVersionManifest(scope, name, versionOrTag, false, true);
Copy link
Member

Choose a reason for hiding this comment

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

加一下 range 的测试用例?

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.

补充一下子 range 相关测试用例,其他没问题了。

@fengmk2
Copy link
Member

fengmk2 commented Jun 6, 2023

cc @hax

@fengmk2
Copy link
Member

fengmk2 commented Jun 6, 2023

@elrrrrrrr 也帮忙看看,今晚合并,然后在 r.cnpmjs.org 跑一下补数据,看看跑完历史数据要多久。

Copy link
Member

@elrrrrrrr elrrrrrrr left a comment

Choose a reason for hiding this comment

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

+1

Copy link
Member

@elrrrrrrr elrrrrrrr left a comment

Choose a reason for hiding this comment

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

+1

Copy link
Member

@elrrrrrrr elrrrrrrr 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 a7fd3a8 into master Jun 6, 2023
@fengmk2 fengmk2 deleted the feat/fast_semver branch June 6, 2023 12:56
fengmk2 pushed a commit that referenced this pull request Jun 6, 2023
[skip ci]

## [3.28.0](v3.27.0...v3.28.0) (2023-06-06)

### Features

* impl fast semver search ([#495](#495)) ([a7fd3a8](a7fd3a8))
@fengmk2
Copy link
Member

fengmk2 commented Jun 6, 2023

大表重建索引要很长时间
image

cc @elrrrrrrr 参考。

@fengmk2
Copy link
Member

fengmk2 commented Jun 6, 2023

大表重建索引要很长时间 image

cc @elrrrrrrr 参考。

[Success] ,耗时:950,047(ms)

@elrrrrrrr elrrrrrrr mentioned this pull request Jun 7, 2023
fengmk2 pushed a commit that referenced this pull request Jun 7, 2023
> follow #495 after supporting
spec, adjust the parameter validation rules
1. 🆕 Add `Spec` validation rule, validating the spec by npa
2. 🛠️ Upgrade versionOrTag to versionSpec to support semver expressions,
such as `^2.x || > 3.x`
---------

> follow #495 支持 spec 后,调整参数校验规则
1. 🆕 新增 `Sepc` 校验规则,使用 npa 拼接包名进行验证
2. 🛠️ versionOrTag 升级为 versionSpec 支持 semver 表达式,例如 `^2.x || > 3.x`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sql include sql change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support list and view raw files 支持 range 接口查询版本
3 participants