42 Commits

Author SHA1 Message Date
killa
297bd7a745 feat: add since for api sync binary (#802) 2025-05-29 08:11:05 +08:00
elrrrrrrr
81620e3ed5 refactor: doc_count & doc_version_count perf (#797)
<!--- SUMMARY_MARKER --->
## Sweep Summary <sub><a href="https://app.sweep.dev"><img
src="https://raw.githubusercontent.com/sweepai/sweep/main/.assets/sweep-square.png"
width="25" alt="Sweep"></a></sub>

Improves database performance by replacing expensive count queries with
a dedicated totals table that's updated asynchronously via events.

- Created a new `totals` table in `app/repository/model/Total.ts` to
store package and version counts instead of running expensive SQL count
queries.
- Implemented `TotalRepository` in `app/repository/TotalRepository.ts`
with methods to increment and retrieve count values.
- Added event handlers in `app/core/event/TotalHandler.ts` that listen
for package and version additions to update counts asynchronously.
- Modified `PackageRepository.queryTotal()` to fetch counts from the
totals table instead of executing direct SQL count queries.
- Added migration scripts in `sql/mysql/4.3.0.sql` and
`sql/postgresql/4.3.0.sql` to create the totals table and populate it
with existing data.

---
[Ask Sweep AI questions about this PR](https://app.sweep.dev)
<!--- SUMMARY_MARKER --->

> Fix database performance issues caused by doc_count and
doc_version_count queries

1. 💽 Add a corresponding totals table to record statistical information
2.  Add a `PACKAGE_ADDED` event and the original
`PACKAGE_VERSION_ADDED` event to asynchronously update records in the
table
3. ♻️ Add a new existing data migration script to migrate the original
statistical information to the totals table

-----------

> 修复 doc_count 和 doc_version_count 查询导致的数据库性能问题

1. 💽 新增对应 totals 表,用来记录统计信息
2.  新增 `PACKAGE_ADDED` 事件,和原有 `PACKAGE_VERSION_ADDED` 事件,异步更新表内记录
3. ♻️ 新增存量数据迁移脚本,迁移原有的统计信息到 totals 表

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced persistent tracking of total package and package version
counts, with real-time updates when new packages or versions are added.
- Added new data models and repository methods to manage and retrieve
these total counts.
- Emitted events upon new package creation to update totals
automatically.

- **Database**
- Added a new "totals" table to both MySQL and PostgreSQL databases for
storing aggregate counts initialized from existing data.

- **Bug Fixes**
- Ensured total counts are always returned as numbers in scheduled data
updates.

- **Tests**
- Added and updated tests to verify correct behavior of total count
tracking, incrementing, resetting, and retrieval.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-04-24 14:23:03 +08:00
killa
080035f7bc feat(sql): add gmt_create for binaries index idx_category_parent_gmt_create (#786)
Include sql change.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced data processing with additional safeguards to limit
iterations during data retrieval, improving stability and preventing
resource overuse.

- **Chores**
- Refined database indexing by removing an old index and adding a new
one, optimizing query performance for faster data access and a smoother
overall experience.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-04-03 14:47:12 +08:00
fengmk2
f240799fa2 feat: support PostgreSQL (#733)
closes https://github.com/cnpm/cnpmcore/issues/731

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Added support for PostgreSQL alongside MySQL, including a new database
setup script and comprehensive documentation for local development.
- Introduced a new CI job for PostgreSQL testing in the GitHub Actions
workflow.
- Enhanced the `README.md` and `DEVELOPER.md` files to provide clearer
instructions for using both database systems.
- Added new environment variable configurations for PostgreSQL in the
Docker deployment documentation.

- **Bug Fixes**
- Improved error handling in tests for duplicate entries to accommodate
both MySQL and PostgreSQL error messages.

- **Documentation**
- Updated setup instructions for PostgreSQL and clarified MySQL setup in
the documentation.
	- Enhanced contributor information in the README.
- Expanded instructions for setting up Elasticsearch and Kibana,
including environment variable configurations.

- **Chores**
- Updated package dependencies to include PostgreSQL client libraries
and modified scripts to support both databases.
	- Changed the base image in the Dockerfile to a newer Node.js version.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-30 21:56:45 +08:00
fengmk2
b0cd0ba387 chore: change 3.63.0.sql (#714) 2024-10-13 10:41:07 +08:00
hezhengxu2018
91aea0f106 feat: proxy mode [sql changed] (#571)
closes https://github.com/cnpm/cnpmcore/issues/366

开启代理模式时如果找不到依赖会直接返回上游仓库的manifest信息并缓存于nfs,当请求的tgz文件不存在时从上游仓库获取并返回,同时创建对应版本的同步任务。每小时检查更新已缓存的manifest文件保证上游仓库发布新版本时不会因为缓存落后而404。

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced proxy cache management for package manifests and versions.
  - Added new HTTP methods for managing proxy caches.
- Implemented scheduled workers for updating and synchronizing proxy
cache.

- **Updates**
  - Expanded `SyncMode` enum to include a new value `proxy`.
- Updated constants with `PROXY_CACHE_DIR_NAME` and
`ABBREVIATED_META_TYPE`.

- **Tests**
- Added comprehensive test cases for `ProxyCacheService`,
`ProxyCacheRepository`, and related controllers.
- Verified functionality of scheduled workers for proxy cache updates
and synchronization.
- Enhanced testing coverage for handling package downloads in proxy
mode.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: fengmk2 <suqian.yf@antgroup.com>
2024-10-13 10:21:57 +08:00
hezhengxu2018
707a1d3809 feat: read remote auth token from database (#595)
closes https://github.com/cnpm/cnpmcore/issues/586
2023-10-11 09:25:17 -05:00
fengmk2
f5607c0a87 fix: ignore fix invalid version (#498) 2023-06-07 08:58:35 +08:00
killa
a7fd3a8c8a feat: impl fast semver search (#495)
Including SQL change: `sql/3.28.0.sql`
2023-06-06 20:56:05 +08:00
elrrrrrrr
3a8a91ae0b feat: token last used at (#488)
> Add the lastUsedBy field to the Token model

* 🧶 Add `lastUsedBy` field to the token, for platform display.
* 🐞 Fix the issue where the graunlarToken is not expired in read-only
scenarios.
------
> 为 Token 模型添加 lastUsedBy 字段
* 🧶 新增 lastUsedBy 字段,记录 token 最近使用时间,用于平台展示
* 🐞 修复 graunlarToken 过期时,只读场景没有禁用的问题
2023-06-01 19:18:17 +08:00
fengmk2
7e63e7f0eb fix: ignore non-file on tar entry filter (#458)
> ENOENT: no such file or directory, stat
'/root/.cnpmcore/downloads/2023/05/06/unpkg_@iov_wallet-providers@1.0.0_0f152162-9cce-4a80-bacc-41271b7aac3f/package'
2023-05-06 01:53:25 +08:00
fengmk2
8ec081acd6 feat: support unpkg features (#456)
WARN: include sql change

😄 Follow unpkg router
😄 Auto sync files after package version add

closes https://github.com/cnpm/cnpmcore/issues/452
2023-05-05 23:22:08 +08:00
elrrrrrrr
92ddf2c8c3 feat: support granular token (#443)
> 🚀 Added implementation related to
[granularToken](https://docs.npmjs.com/about-access-tokens#about-granular-access-tokens),
mainly used for web authorization scenarios.

* 📝 Added `1.14.0.sql` to add fields and `token_packages` for
granularToken.
* 🛣️ Added gat related routes, including `create`, `query`, and `delete`
api.
* 🌟 Added `tokenService` to check granularToken access.
* 🔄 Modified Token to perform options and data attribute conversions
internally in the model.
-----------

> 🚀 新增
[granularToken](https://docs.npmjs.com/about-access-tokens#about-granular-access-tokens)
相关实现,主要用于 web 端授权场景
* 📝 新增 `1.14.0.sql` 添加 granularToken 相关字段及 `token_packages` 中间表
* 🛣️ 新增 gat 相关路由,包括`创建`、`查询`、`删除`接口
* 🌟 新增 `tokenService` ,处理 granularToken 鉴权
* 🔄 修改 Token ,在 model 内部进行 options 和 data 属性转换
2023-04-20 15:27:26 +08:00
LiWanglin
1b8512b321 feat: support webauthn (#422)
1. webauth 由 authentication 改造为 session,并增加 web 登录页面,更安全
2. 支持 webauthn 的登录方式,可通过配置控制(默认关闭),更高效

---------------

1. use session instead http authentication on webauth
2. support [webauthn](https://webauthn.guide/), you should set
`enableWebAuthn: true` in the configuration

closes https://github.com/cnpm/cnpmcore/issues/236

---------

Co-authored-by: lanxiu.lwl <lanxiu.lwl@alipay.com>
Co-authored-by: elrrrrrrr <elrrrrrrr@gmail.com>
2023-03-27 18:27:07 +08:00
fengmk2
e40c5021bb 🐛 FIX: Mirror cypress arm64 binary (#351) 2022-11-06 18:46:17 +08:00
elrrrrrrr
28eeeafd98 fix: registry host config (#346)
closes #343
2022-10-28 00:03:10 +08:00
elrrrrrrr
a91c8ac4d0 feat: sync package from spec regsitry (#293) 2022-08-22 21:12:41 +08:00
elrrrrrrr
4b506c8371 feat: init registry & scope (#286) 2022-08-17 17:38:55 +08:00
killa
79cb82615f feat: impl migration sql (#290) 2022-08-16 23:51:36 +08:00
killa
4cfa8ed9d6 feat: impl hooks api (#287)
* feat: impl hooks api

Refs:
- https://github.com/cnpm/cnpmcore/issues/282
- https://github.com/npm/registry/blob/master/docs/hooks/endpoints.md
2022-08-16 16:56:26 +08:00
killa
47d53d22ad feat: add bizId for task (#285)
* feat: add bizId for task

impl idempotent save for task

Refs:
- https://github.com/cnpm/cnpmcore/issues/282
2022-08-16 16:54:45 +08:00
fengmk2
7cfbc10073 🤖 TEST: Add upper case tests 2022-03-25 22:03:51 +08:00
fengmk2
34ab631ef9 🐛 FIX: Support package name case sensitive 2022-03-25 22:03:51 +08:00
fengmk2
18ca633b73 📦 NEW: Store package version manifest to database (#190)
Disable by default
2022-03-22 20:22:58 +08:00
fengmk2
1ae4ece8d1 📦 NEW: Support block package by admin (#172) 2022-02-13 12:48:11 +08:00
fengmk2
a79e126819 👌 IMPROVE: add idx_packageid_yearmonth index on package_version_downloads (#133)
https://github.com/cnpm/cnpmcore/issues/132#issuecomment-1025058266
2022-01-30 11:36:43 +08:00
fengmk2
26408fd1b0 🐛 FIX: Download scope too long than package_id (#81)
```
ER_DATA_TOO_LONG: Data too long for column 'package_id' at row 1
```
2022-01-03 23:18:59 +08:00
fengmk2
9c318331fa 📦 NEW: Support binary sync worker (#80) 2022-01-03 22:37:42 +08:00
fengmk2
a36f8d3479 📦 NEW: Support changes stream (#73)
closes https://github.com/cnpm/cnpmcore/issues/70
2021-12-26 22:15:26 +08:00
fengmk2
98d5675c14 👌 IMPROVE: Support cnpmjs.org tar download url style 2021-12-20 14:43:58 +08:00
fengmk2
e810821eb6 🐛 FIX: Ignore npm: prefix on maintainer name (#57) 2021-12-19 13:21:53 +08:00
fengmk2
6fdbd5fc74 🐛 FIX: dists table should not has path unique key (#51) 2021-12-18 22:18:50 +08:00
fengmk2
82510eab5a 🐛 FIX: Dist name length up to varchar(220) (#37)
closes https://github.com/cnpm/cnpmcore/issues/36
2021-12-14 23:34:06 +08:00
fengmk2
22d0e725ae 🤖 TEST: Test on OSS NFS store (#24) 2021-12-12 17:56:17 +08:00
fengmk2
bdeadf9c74 📦 NEW: Impl sync package like cnpmjs.org (#23)
- Task list base on MySQL
2021-12-12 12:50:41 +08:00
fengmk2
4dccafcc0b feat: UserRoleManager and developer document (#16) 2021-12-07 16:36:35 +08:00
fengmk2
5f3400fad8 feat: impl Token/Maintainer/User 2021-12-07 01:01:54 +08:00
fengmk2
ac4d5862db feat: validate npm package name
by https://github.com/npm/validate-npm-package-name
2021-12-07 01:01:54 +08:00
fengmk2
0af0ecadd5 feat: support package downloads api (#10)
[x] refactor: prepare database before run test
2021-11-23 11:09:38 +08:00
fengmk2
0c56fb36ef feat: impl GET /:name list full manifests API (#7)
tracing async function timer with AsyncTimer decorator
2021-11-21 01:24:32 +08:00
fengmk2
deab665d18 feat: Impl PUT /:name HTTP API (#5)
Supoort add new version, show version and download version tar.
Only support node >= 16.13.0 for (fs|stream/promises) API

closes https://github.com/cnpm/cnpmcore/issues/4
2021-11-14 23:08:10 +08:00
killagu
eaa7b61c12 Init project structure 2021-09-09 21:57:34 +08:00