Skip to content

Conversation

DuckDuckStudio
Copy link
Owner

@DuckDuckStudio DuckDuckStudio commented Sep 27, 2025

此次优化重构了 URL 检查结果处理逻辑。
在第一次检查一个 URL 时,将 URL 和检查结果一起存入 checkedUrls 中;
如果后续再次检查这个 URL,则使用先前检查的结果。


对比测试:


@DuckDuckStudio DuckDuckStudio self-assigned this Sep 27, 2025
@DuckDuckStudio DuckDuckStudio added DEV-开发分支合并 开发分支的合并PR DEV-未经测试 未经测试或无法测试的项 优化 优化某些功能 DEV-测试错误 未通过测试 DEV-需要注意 DEV:需要注意的任务,可能含有重要信息 and removed DEV-未经测试 未经测试或无法测试的项 labels Sep 27, 2025
@DuckDuckStudio
Copy link
Owner Author

DuckDuckStudio commented Sep 27, 2025

GitHub Action Run 18054481111 Crash Report.

Error:  winget-pkgs/manifests/2/2BrightSparks/SyncBackPro/11.2.33.0/2BrightSparks.SyncBackPro.installer.yaml 中的 https://www.2brightsparks.com/assets/software/SyncBack/SyncBackPro64_Setup.11.2.33.0.exe 发生错误: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
Unhandled exception. System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.HashSet`1.Enumerator.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at checker.Program.CheckUrlAsync(HttpClient client, String filePath, String url, String failureLevel) in /home/runner/work/winget-tools/winget-tools/checker/Program.cs:line 259
   at checker.Program.<>c__DisplayClass3_0.<<CheckUrlsInYamlFilesParallel>b__0>d.MoveNext() in /home/runner/work/winget-tools/winget-tools/checker/Program.cs:line 129
--- End of stack trace from previous location ---
   at checker.Program.CheckUrlsInYamlFilesParallel(String folderPath, String failureLevel, Int32 maxConcurrency) in /home/runner/work/winget-tools/winget-tools/checker/Program.cs:line 141
   at checker.Program.Main(String[] args) in /home/runner/work/winget-tools/winget-tools/checker/Program.cs:line 75
   at checker.Program.<Main>(String[] args)
**********************************************************************************************************************
Error: Process completed with exit code 134.

翻译:
操作非并发集合时必须具有独占访问权限。该集合上执行了并发更新操作,导致其状态损坏。集合状态不再正确。
未处理的异常。System.InvalidOperationException: 集合已被修改;枚举操作可能无法执行。

@DuckDuckStudio DuckDuckStudio added DEV-未经测试 未经测试或无法测试的项 and removed DEV-测试错误 未通过测试 labels Sep 27, 2025
@DuckDuckStudio
Copy link
Owner Author

依据实际结果,这个优化似乎对 默认 失败等级的运行时间没有明显优化,但对 详细 失败等级的运行时间有明显优化。
这也是预期中的。

@DuckDuckStudio
Copy link
Owner Author

除了重复检查,超时也是影响检查时间的一大因素。但我们似乎只能通过忽略来处理这些超时的 URL。

@DuckDuckStudio DuckDuckStudio marked this pull request as ready for review September 27, 2025 10:02
@DuckDuckStudio DuckDuckStudio added DEV-测试通过 通过测试 and removed DEV-未经测试 未经测试或无法测试的项 DEV-需要注意 DEV:需要注意的任务,可能含有重要信息 labels Sep 27, 2025
@DuckDuckStudio
Copy link
Owner Author

我可能会考虑延迟这个 PR 的合并,因为这个优化尚不能证明稳定,且详细模式很少用到。

Copy link
Collaborator

@fjwxzde fjwxzde left a comment

Choose a reason for hiding this comment

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

这里有一些建议。
另外,在处理错误结果时都是

errorMessage = $"";
checkedUrls.TryAdd(url, errorMessage);
WriteErrorMessage(errorMessage, filePath);

的格式,也许我们可以建一个方法来统一这些?


Console.WriteLine("[INFO] 正在查找 URL...");

// 先收集所有 URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

由于现在没有去重,这里的收集也许可以简化?

Copy link
Owner Author

Choose a reason for hiding this comment

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

我不知道该怎么简化。

Comment on lines +459 to +460
errorMessage = $"\n[Debug] 访问 <ManifestFilePath> 中的 {url} 时发生错误: {e.Message} (资源暂时不可用)";
checkedUrls.TryAdd(url, errorMessage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个结果似乎也不应存储?

Copy link
Owner Author

Choose a reason for hiding this comment

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

我不确定发布者多久能修复这个错误。
另外,有些发布者的网站将 404 Not Found 视为资源暂时不可用。

Copy link
Collaborator

Choose a reason for hiding this comment

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

另外,有些发布者的网站将 404 Not Found 视为资源暂时不可用。

这应该只是页面描述,实际应该还是响应 404。

Comment on lines +540 to +541
errorMessage = $"\n[Debug] 访问 <ManifestFilePath> 中的 {url} 时超时: {e.Message}";
checkedUrls.TryAdd(url, errorMessage);
Copy link
Collaborator

@fjwxzde fjwxzde Sep 27, 2025

Choose a reason for hiding this comment

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

除了重复检查,超时也是影响检查时间的一大因素。但我们似乎只能通过忽略来处理这些超时的 URL。

也许这里存储超时结果能缓解超时 URL 带来的时间,但也许我们不该存储超时结果,因为它可能在后续缓解?
亦或者我们应该抛出 TimeoutException 让下面的 catch (TimeoutException e) 处理?

Copy link
Owner Author

Choose a reason for hiding this comment

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

我觉得还是保持原样,在 catch 里抛出并不会被下面的 catch 捕获。

Co-authored-by: 宁静致远 <172552290+fjwxzde@users.noreply.github.com>
@DuckDuckStudio
Copy link
Owner Author

DuckDuckStudio commented Sep 28, 2025

另外,在处理错误结果时都是

errorMessage = $"";
checkedUrls.TryAdd(url, errorMessage);
WriteErrorMessage(errorMessage, filePath);

的格式,也许我们可以建一个方法来统一这些?

我认为还是保留原样。有些 errorMessage 在失败模式 默认 和 详细 下有不同的 errorMessage。
在这种情况下,处理错误结果是这样的:

errorMessage = $"...";
if (failureLevel == "详细")
{
    errorMessage = string.Concat(errorMessage, $"[Hint] Sundry 命令: ...");
}
checkedUrls.TryAdd(url, errorMessage);
WriteErrorMessage(errorMessage, filePath);
if (failureLevel == "详细")
{
    return false;
}

@DuckDuckStudio DuckDuckStudio removed the 处理中 正在处理中... label Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV-开发分支合并 开发分支的合并PR DEV-测试通过 通过测试 优化 优化某些功能
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pref(checker): 不要重复检查相同的 URL
2 participants