Conversation
Member
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 旨在修复 ScriptCat 在长时间运行、频繁浏览/请求场景下可能出现的内存泄漏与资源累积问题:一方面限制 URL 匹配缓存规模避免无限增长,另一方面在 GM_xmlhttpRequest 的异常/完成路径上补齐连接与等待态引用的清理,减少无效监听器与 Promise 引用残留。
Changes:
- 为
UrlMatch的 URL 匹配缓存增加默认 4096 条的 LRU 上限,并在命中时刷新最近使用顺序。 - 增加
UrlMatch缓存上限与 LRU 行为的回归测试。 - 在 GM_xmlhttpRequest 相关实现中补齐
nwErrorResultPromises清理,并确保 content 侧连接在清理时断开以避免长期累积。
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/pkg/utils/match.ts | 为 UrlMatch 引入带上限的 LRU 缓存,避免缓存随不同 URL 访问无限增长 |
| src/pkg/utils/match.test.ts | 新增缓存上限与“最近使用刷新”的回归测试用例 |
| src/app/service/service_worker/gm_api/gm_xhr.ts | fetch 策略等待网络错误结果后删除 nwErrorResultPromises 条目,减少残留引用 |
| src/app/service/service_worker/gm_api/gm_api.ts | 在请求结束/异常清理路径中补齐 nwErrorResultPromises 的删除,避免 map 长期堆积 |
| src/app/service/content/gm_api/gm_xhr.ts | 在清理函数中确保断开 connect,并在 code=-1 错误路径上避免重复完成导致的资源残留 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist / 检查清单
Description / 描述
变更内容
Screenshots / 截图