Skip to content

Refactor node pre check#8848

Merged
2dust merged 8 commits into2dust:masterfrom
DHR60:refactor_check
Feb 28, 2026
Merged

Refactor node pre check#8848
2dust merged 8 commits into2dust:masterfrom
DHR60:refactor_check

Conversation

@DHR60
Copy link
Copy Markdown
Contributor

@DHR60 DHR60 commented Feb 26, 2026

Fix #8823

重构 PreCheck,使其符合现在的配置生成结构

  • 错误类型将分为 Error 和 Warning 两种,只有 Error 不为空时表示配置有问题,生成的 context 不可信
  • Build 和 Precheck 统一,避免读取两次数据库
  • 如果组内配置有问题那么先跳过并从组中删除。如果组为空直接 Error 出来;如果组不为空则将组内配置 Error 降级为 Warning

国际化还没做

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 26, 2026

然后打算做这个 #8824 (comment)

基于这个 pr

@2dust
Copy link
Copy Markdown
Owner

2dust commented Feb 26, 2026

实际上完全可以避免,无论是手动添加到策略组还是链式代理。
在 ProtocolExtra 里储存下手动添加节点的快照,数据库优先,快照作为 Fallback。
这也是我积极重构节点储存的其中一个原因

你是说要做这个快照吗?这个不建议做。
更新订阅后,节点没有了说明已经不支持了,你快照了也不通。
或者是我没有理解对?

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 26, 2026

实际上完全可以避免,无论是手动添加到策略组还是链式代理。
在 ProtocolExtra 里储存下手动添加节点的快照,数据库优先,快照作为 Fallback。
这也是我积极重构节点储存的其中一个原因

你是说要做这个快照吗?这个不建议做。 更新订阅后,节点没有了说明已经不支持了,你快照了也不通。 或者是我没有理解对?

ProtocolExtraItem 里 public List<ProfileItem>? FallbackChildItems { get; init; }

直接存 ChildItems 对应的全量 FallbackChildItems,比如如果是组,也展开到组内自己的 FallbackChildItems,依次递归下去,读取时先读数据库,再读 FallbackChildItems
所以所有手动添加的,即使数据库里删了还是有的

节点失效导致不通,用户自己 ctrl + a 右键再重建一个就好了。这也符合正常交互逻辑

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 26, 2026

或者说有什么更简便的方式,解决右键 “多选生成配置组”,但订阅更新后直接不能用的问题吗?

@2dust
Copy link
Copy Markdown
Owner

2dust commented Feb 26, 2026

或者说有什么更简便的方式,解决右键 “多选生成配置组”,但订阅更新后直接不能用的问题吗?

如果是鸡场的订阅,策略组中多选了配置后产生,这个没有好办法,只能是变成自定义配置存储起来,但是一样服务端也会失效导致不能用。
总得来说用鸡场的,建议直接用 mihomo 配置 或用策略组的第一个过滤方式。

自建的不讨论,基本没有问题。

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 26, 2026

这个确实会失效导致不能用

但是从正常 UX 角度看

节点失效导致不通,用户自己 ctrl + a 右键再重建一个就好了

这个很明显更合理,并且利大于弊。

相比于服务端会失效导致不能用,更新订阅后导致策略组不能用的用户体验显然更不好

并且只影响被删除节点的处理,其他的还是按部就班正常处理

同时打算和 pre check 以及 group pre view 联动,标明哪个子配置是被删除的,哪个子配置是过期的

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 26, 2026

或者我还有个想法,和那个一键测速一样

右键加一个 Builtin 添加策略组,目标是整个订阅分组。
原来的多选创建保留

正则筛选中预置 ^(?!.*(剩余|过期|到期|重置)).*$

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 26, 2026

或者我还有个想法,和那个一键测速一样

右键加一个 Builtin 添加策略组,目标是整个订阅分组。 原来的多选创建保留

正则筛选中预置 ^(?!.*(剩余|过期|到期|重置)).*$

这种可能更合理,并且对机场用户更方便一点

也可以加入 Builtin 地区筛选,比如点击就添加 $"{subItem.Remarks}-日本",正则:日本|[Jj][Pp]|🇯🇵
日本,香港,新加坡的都加进去。先预获取一遍,如果这个地区为空则删除

@2dust
Copy link
Copy Markdown
Owner

2dust commented Feb 27, 2026

或者我还有个想法,和那个一键测速一样

右键加一个 Builtin 添加策略组,目标是整个订阅分组。 原来的多选创建保留

正则筛选中预置 ^(?!.*(剩余|过期|到期|重置)).*$

可以加这个,然后把右键多选生成策略组的删除了,入口统一。
多选的这个功能真没有必要花太多时间搞了,现在已经对自建够用了。

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 27, 2026

那就右键添加后,不自动激活,isSub = false

然后把多选创建的删了

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 27, 2026

这个 pr 已经 ready 了

可能 Builder 和 数据类 的位置有点问题,没想出更好的位置

@2dust
Copy link
Copy Markdown
Owner

2dust commented Feb 27, 2026

感谢,等测试下

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the “pre-check” flow by replacing ActionPrecheckManager with a new CoreConfigContextBuilder + NodeValidator pipeline that builds the config context once, returns structured Errors vs Warnings, and supports skipping invalid nodes inside groups (to address unsupported servers stopping group/balancer behavior, per #8823).

Changes:

  • Replace centralized precheck manager with CoreConfigContextBuilder / NodeValidator producing (context, errors, warnings) in one pass.
  • Update reload/export paths to proceed on warnings but stop on errors, and reuse the built CoreConfigContext to avoid duplicate DB reads.
  • Rename/expand i18n resource keys for the new validator messages and add new routing/group/subscription warning/error messages.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs Uses CoreConfigContextBuilder.Build for export and continues on warnings only.
v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs Builds context once during reload and passes it to core load to avoid rebuilding.
v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs Removes cycle pre-check when adding group nodes.
v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx Renames/updates message keys and adds new validator messages (zh-Hant).
v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx Renames/updates message keys and adds new validator messages (zh-Hans).
v2rayN/ServiceLib/Resx/ResUI.ru.resx Renames/updates message keys and adds new validator messages (ru).
v2rayN/ServiceLib/Resx/ResUI.resx Renames/updates message keys and adds new validator messages (default).
v2rayN/ServiceLib/Resx/ResUI.hu.resx Renames/updates message keys and adds new validator messages (hu).
v2rayN/ServiceLib/Resx/ResUI.fr.resx Renames/updates message keys and adds new validator messages (fr).
v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx Renames/updates message keys and adds new validator messages (fa-Ir).
v2rayN/ServiceLib/Resx/ResUI.Designer.cs Regenerated strongly-typed resource accessors for renamed/new message keys.
v2rayN/ServiceLib/Models/CoreConfigContext.cs Adds RunCoreType to persist selected runtime core type in the context.
v2rayN/ServiceLib/Manager/GroupProfileManager.cs Changes GetAllChildProfileItems to return a dictionary (IndexId → ProfileItem).
v2rayN/ServiceLib/Manager/CoreManager.cs LoadCore now takes CoreConfigContext? instead of ProfileItem?; speedtest uses builder.
v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs Removed (replaced by builder/validator flow).
v2rayN/ServiceLib/Handler/CoreConfigHandler.cs Uses builder/resolve APIs for speedtest config generation.
v2rayN/ServiceLib/Handler/Builder/NodeValidator.cs New validator that produces structured errors/warnings.
v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs New context builder that registers proxies, handles groups, routing outbound resolution, and subscription chain nodes.
v2rayN/ServiceLib/GlobalUsings.cs Adds global using for ServiceLib.Handler.Builder.
Files not reviewed (1)
  • v2rayN/ServiceLib/Resx/ResUI.Designer.cs: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 27, 2026

#8848 (comment)
这个确实是 Bug,我的 Copilot 偷懒了应该是

@DHR60
Copy link
Copy Markdown
Contributor Author

DHR60 commented Feb 27, 2026

#8848 (comment)

这个转为 Build 阶段内部处理,允许一定程度上的错误

@2dust 2dust merged commit 584e538 into 2dust:master Feb 28, 2026
@2dust
Copy link
Copy Markdown
Owner

2dust commented Feb 28, 2026

接下来合并 #8855

@DHR60 DHR60 deleted the refactor_check branch February 28, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Skipping unsupported servers

3 participants