-
Notifications
You must be signed in to change notification settings - Fork 84
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: proxy模式增强 #724
base: master
Are you sure you want to change the base?
feat: proxy模式增强 #724
Conversation
fangzhengjin
commented
Nov 1, 2024
•
edited
Loading
edited
- 刷新代理缓存时,如果source仓库找不到(404)时,尝试在private仓库中查找,以private仓库查询结果返回
- 刷新代理缓存时,如果在同时在source与private中找到,则将private结果中的versions与time数组合并至source查询的结果中(只合并source中不存在的key)
- 当在private中推送私有包时,立即从private库中刷新该包的缓存信息,可即时被查询或下载,无需等待凌晨3点刷新缓存
Warning Rate limit exceeded@fangzhengjin has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 4 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Hey @fangzhengjin, here is an example of how you can ask me to improve this pull request: @Sweep Add unit tests for the updated `getPackageManifest` method to verify error handling behavior when cache retrieval fails 📖 For more information on how to use Sweep, please read our documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
app/core/service/ProxyCacheService.ts (1)
184-194
: Avoid variable shadowing of 'manifest'Within the
if (status === 404)
block, the variablemanifest
is redefined when destructuring fromdata
, which can lead to confusion due to variable shadowing. Consider renaming the innermanifest
variable to avoid this issue.Apply this diff to rename the variable:
- const { etag, data: manifest, blockReason } = ... + const { etag, data: privateManifest, blockReason } = ...And update the return statement:
- return manifest as any; + return privateManifest as any;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
app/core/service/ProxyCacheService.ts
(6 hunks)
🧰 Additional context used
📓 Learnings (1)
app/core/service/ProxyCacheService.ts (3)
Learnt from: hezhengxu2018
PR: cnpm/cnpmcore#571
File: app/core/service/ProxyCacheService.ts:161-209
Timestamp: 2024-10-09T03:45:47.108Z
Learning: In the `ProxyCacheService` class, requests to the upstream repository already throw an error if they fail, making additional checks for the response status unnecessary.
Learnt from: hezhengxu2018
PR: cnpm/cnpmcore#571
File: app/core/service/ProxyCacheService.ts:161-209
Timestamp: 2024-10-09T03:45:48.990Z
Learning: In the `ProxyCacheService` class, requests to the upstream repository already throw an error if they fail, making additional checks for the response status unnecessary.
Learnt from: hezhengxu2018
PR: cnpm/cnpmcore#571
File: app/core/service/ProxyCacheService.ts:161-209
Timestamp: 2024-07-19T06:26:05.533Z
Learning: In the `ProxyCacheService` class, requests to the upstream repository already throw an error if they fail, making additional checks for the response status unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (3)
app/core/service/ProxyCacheService.ts (1)
218-225
: Add timestamp validation for time mergingThe time merging logic should validate timestamp formats to prevent invalid dates.
Consider adding timestamp validation:
if (manifest.time) { const privateTimeMap = data?.time || {}; for (const key in privateTimeMap) { + const timestamp = privateTimeMap[key]; + if (!timestamp || isNaN(Date.parse(timestamp))) continue; if (!manifest.time[key]) { manifest.time[key] = privateTimeMap[key]; } } }app/port/controller/package/UpdatePackageController.ts (2)
74-74
: Maintain consistency in comment languageThe comment on line 74 is in Chinese:
// 代理模式下,更新代理缓存
. To maintain consistency across the codebase, consider translating comments to English.
79-79
: Maintain consistency in comment languageThe comment on line 79 is in Chinese:
// 仅manifests需要更新,指定版本的package.json文件发布后不会改变
. To maintain consistency across the codebase, consider translating comments to English.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
app/core/service/ProxyCacheService.ts
(6 hunks)app/port/controller/package/UpdatePackageController.ts
(3 hunks)
🧰 Additional context used
📓 Learnings (1)
app/core/service/ProxyCacheService.ts (3)
Learnt from: hezhengxu2018
PR: cnpm/cnpmcore#571
File: app/core/service/ProxyCacheService.ts:161-209
Timestamp: 2024-10-09T03:45:47.108Z
Learning: In the `ProxyCacheService` class, requests to the upstream repository already throw an error if they fail, making additional checks for the response status unnecessary.
Learnt from: hezhengxu2018
PR: cnpm/cnpmcore#571
File: app/core/service/ProxyCacheService.ts:161-209
Timestamp: 2024-10-09T03:45:48.990Z
Learning: In the `ProxyCacheService` class, requests to the upstream repository already throw an error if they fail, making additional checks for the response status unnecessary.
Learnt from: hezhengxu2018
PR: cnpm/cnpmcore#571
File: app/core/service/ProxyCacheService.ts:161-209
Timestamp: 2024-07-19T06:26:05.533Z
Learning: In the `ProxyCacheService` class, requests to the upstream repository already throw an error if they fail, making additional checks for the response status unnecessary.
🔇 Additional comments (6)
app/core/service/ProxyCacheService.ts (4)
20-20
: LGTM: PackageManagerService integration
The PackageManagerService dependency is correctly imported and injected following the established pattern.
Also applies to: 55-56
66-76
: LGTM: Robust error handling for cache retrieval
The error handling implementation is well-structured:
- Gracefully handles cache misses
- Properly logs errors without breaking execution
- Uses correct context in log messages
Line range hint 197-226
: Optimize version map merging logic
The current implementation of merging private and public versions could be more efficient and safer.
Consider refactoring to use a more functional approach:
- const privateVersionMap = data?.versions || {};
- for (const key in privateVersionMap) {
- if (!versionMap[key]) {
- versionMap[key] = privateVersionMap[key];
- }
- }
+ manifest.versions = {
+ ...privateVersionMap,
+ ...versionMap,
+ };
Also, consider adding a lock or synchronization mechanism to prevent potential race conditions during version map updates.
184-194
: Consider adding manifest validation
The code handles 404 status and private package retrieval, but there's no validation of the manifest structure before processing.
Consider adding validation before processing the manifest:
const { status, data: { manifest } } = responseResult;
+if (!manifest || typeof manifest !== 'object') {
+ throw new Error('Invalid manifest structure received');
+}
// sourceRegistry not found, check private package
app/port/controller/package/UpdatePackageController.ts (2)
20-22
: Imports are properly added
The modules SyncMode
, ProxyCacheRepository
, isPkgManifest
, and ProxyCacheService
are correctly imported and used in the code.
36-39
: Dependency injection setup is correct
The dependencies proxyCacheRepository
and proxyCacheService
are properly injected as private readonly
class properties with the @Inject()
decorator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
app/core/service/ProxyCacheService.ts
(5 hunks)app/port/controller/package/UpdatePackageController.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- app/core/service/ProxyCacheService.ts
c54a9e4
to
3aea4c8
Compare
@fengmk2 空了麻烦看下有啥要调整的 |