Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 本次拉取请求旨在全面提升 GitHub 资源的访问速度和稳定性。通过引入一个全新的加速模块,系统现在能够提供更灵活的代理配置、智能的重试机制以及高效的静态资源缓存,显著优化了用户体验,并解决了之前版本中存在的评审问题。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
背景
原先的 GitHub 加速只是在
Hooks里做一次简单的 URL 改写,问题是:这个 PR 把 GitHub 加速重构成独立模块,并补上请求前拦截、代理选择、失败重试和小体积静态资源缓存。
核心设计
1. Arc 层补丁:为
Http增加请求前拦截能力修改
patches/arc/0001-API-Http.onBeforeRequest.patch,给arc.util.Http增加一个轻量级的请求前扩展点:Http.onBeforeRequest,在HttpRequest.block/submit进入真实网络访问前触发。HttpRequest暴露当前请求的success回调,便于在 hook 中包装成功逻辑而不是只做 URL 替换。HttpRequest新增directResponse,允许 hook 在命中本地缓存等场景下直接短路返回,不再访问网络。HttpResponse.ofBytes(...)用于构造这类直接返回的响应。这样 GitHub 加速不需要继续把逻辑塞进全局的“字符串替换”里,而是可以在请求对象层面安全地处理缓存命中、镜像切换和重试。
2. 新增
GithubAcceleration模块新增
src/mindustryX/features/GithubAcceleration.kt,统一管理 GitHub 请求的代理、缓存和重试。请求处理链路如下:
Hooks.beforeInit()中初始化模块,并注册Http.onBeforeRequest。https://proxy/.../https://github...这类已包裹 URL 还原成原始 GitHub URL,避免重试链路重复套代理。github.com*.github.comgithubusercontent.com*.githubusercontent.comapi.github.com单独识别 API 请求,和 release / raw / asset 资源走不同代理选择策略。X-MDTX-GH-Original:记录原始 URL,保证重试时回到未代理地址再重新选镜像。X-MDTX-GH-Attempt:记录当前重试次数。GET请求且本地缓存命中,则直接构造directResponse返回。req.url。GET请求包装成功/失败回调:3. 代理模型与选择策略
代理配置使用
ProxyConfig,支持:默认提供三项:
github.comghproxykgithub策略细节:
apiEnabled的代理。assetEnabled的代理。min(maxRetries, enabledProxyCount),避免重试次数超过实际可用代理数。4. 缓存策略
缓存只针对非 API 的
GET请求,避免把 GitHub API 返回内容混入本地缓存。实现细节:
data/cache/gh-acceleration<sha1>.bincacheExpireMinutes判断文件lastModifiedcontentLength在1..2 MiB之间时写缓存HttpResponse.ofBytes(200, bytes)这样缓存覆盖的是
raw.githubusercontent.com、release 小资源等高频静态请求,而不会把未知大小的大资源无上限拉进内存缓存。5. 重试实现
重试只对
GET请求启用,避免对可能有副作用的写请求做重复提交。失败重试时会克隆原请求,并保留这些上下文:
timeoutfollowRedirectsincludeCredentialscontentcontentStream这样可以保证重试是基于“原始请求”重建,而不是在已经被代理改写过的 URL 上继续叠加状态。
设置与 UI
设置项
在中英文 bundle 中新增 GitHub 加速配置项,支持:
代理列表通过
SettingsV2.Data<List<ProxyConfig>>持久化,使用 UBJson 保存,支持:快捷入口
在
NewToolTable增加GH按钮:兼容处理
保留旧配置名兼容迁移:
githubAcceleration.enabled增加对旧githubMirror的 fallback这样用户升级后不会直接丢失旧的“是否开启 GitHub 加速”配置。
清理与替换
Hooks中旧的简单 URL 改写逻辑。VarsX中旧的githubMirror直接配置项,改由新模块统一接管。本次额外修正的评审问题
这个分支在重构基础上又额外修了两点 review feedback:
getResultAsStream()流式读取行为,避免影响大文件下载路径;只有缓存命中的directResponse才会基于内存字节数组返回流。影响范围
主要改动文件:
patches/arc/0001-API-Http.onBeforeRequest.patchsrc/mindustryX/features/GithubAcceleration.ktsrc/mindustryX/Hooks.javasrc/mindustryX/features/ui/toolTable/NewToolTable.ktassets/bundles/bundle-mdtx.propertiesassets/bundles/bundle-mdtx_en.properties备注
main。gh-issue分支,不涉及其他 PR。