Merged
Conversation
Contributor
Author
|
@sourcery-ai review |
审查者指南重构 MyImage 的加载与裁剪行为,以改进异步图片下载与缓存;增加共享下载任务去重与更安全的临时文件处理;微调列表项徽标的渲染效果;并在读取图片时放宽位图文件共享限制。 MyImage 异步下载、缓存与回退的时序图sequenceDiagram
actor WPF as WPFFramework
participant MI as MyImage
participant Disp as Dispatcher
participant Tasks as DownloadTasks
participant Http as HttpRequestBuilder
WPF->>MI: Initialized event
MI->>MI: Load
MI->>Disp: BeginInvoke(async delegate)
activate Disp
Disp->>MI: Async lambda execution
MI->>MI: ActualSource = LoadingSource
MI->>Tasks: GetOrAdd(Url, DownloadImage)
alt New task for Url
Tasks->>MI: Returns new Task for Url
MI->>Http: Create(Url).SendAsync()
Http-->>MI: HttpResponseMessage
MI->>MI: Save stream to temp file
MI->>MI: Move to cache path
MI-->>Tasks: Return temp path
else Existing task for Url
Tasks-->>MI: Existing Task for Url
end
MI->>Tasks: await Task for Url
alt Url download succeeded
MI->>MI: ActualSource = urlTempPath
Disp-->>MI: Async lambda returns
else Url download failed or returned empty
MI->>Tasks: GetOrAdd(FallbackSource, DownloadImage)
alt New task for FallbackSource
Tasks->>MI: Returns new Task for FallbackSource
MI->>Http: Create(FallbackSource).SendAsync()
Http-->>MI: HttpResponseMessage
MI->>MI: Save stream to temp file
MI->>MI: Move to fallback cache path
MI-->>Tasks: Return fallback temp path
else Existing task for FallbackSource
Tasks-->>MI: Existing Task for FallbackSource
end
MI->>Tasks: await Task for FallbackSource
alt Fallback succeeded
MI->>MI: ActualSource = fallbackTempPath
else Fallback failed or returned empty
MI->>MI: Try load from local cache for Url
end
end
Disp-->>WPF: UI updated with ActualSource
MyImage、MyBitmap 与 MyListItem 交互的更新类图classDiagram
class MyImage {
+CornerRadius CornerRadius
+String Source
+String LoadingSource
+String FallbackSource
+Boolean EnableCache
-String _ActualSource
+String ActualSource
-Shared ConcurrentDictionary~String, Task~String~~ _downloadTasks
+Sub Load()
+Sub UpdateClip()
+Shared Function GetTempPath(Url As String) String
-Shared Async Function DownloadImage(url As String) Task~String~
}
class MyBitmap {
+Sub New()
+Sub LoadFromPath(FilePathOrResourceName As String)
}
class MyListItem {
+String Title
+String Info
+String Logo
+Object Tags
+Object Tag
+Object PathLogo
+Sub New()
}
MyListItem "1" o-- "1" MyImage : PathLogo
MyBitmap ..> MyImage : loads image files for
MyImage ..> ConcurrentDictionary : uses
class ConcurrentDictionary {
+Function GetOrAdd(key As String, valueFactory As Func~String, Task~String~~) Task~String~
+Function Remove(key As String, value As Task~String~) Boolean
}
DownloadImage 临时文件处理与清理的流程图flowchart TD
A[Start DownloadImage url] --> B[Compute tempPath = GetTempPath url]
B --> C[Compute TempDownloadingPath = tempPath + random]
C --> D[CreateDirectory GetPathFromFullPath tempPath]
D --> E[Create FileStream TempDownloadingPath]
E --> F[SendAsync HttpRequestBuilder for url]
F --> G{response.EnsureSuccessStatusCode}
G -->|Success| H[Get response.AsStreamAsync]
H --> I[Copy network stream to FileStream]
I --> J[Dispose streams]
J --> K[File.Move TempDownloadingPath to tempPath]
K --> L[Return tempPath]
G -->|Throws exception| X[Catch Exception]
X --> M{File.Exists tempPath}
M -->|Yes| N[File.Delete tempPath]
M -->|No| O[Skip delete tempPath]
N --> P{File.Exists TempDownloadingPath}
O --> P
P -->|Yes| Q[File.Delete TempDownloadingPath]
P -->|No| R[Skip delete TempDownloadingPath]
Q --> S[Log failure with url and tempPath]
R --> S
S --> T[Return String.Empty]
T --> U[End]
文件级变更
针对关联 Issue 的评估
提示与命令与 Sourcery 交互
自定义你的使用体验访问你的 dashboard 以:
获取帮助Original review guide in EnglishReviewer's GuideRefactors MyImage’s loading and clipping behavior to improve async image downloading and caching, adds shared download task de-duplication and safer temp file handling, tweaks list item logo rendering, and relaxes bitmap file sharing when reading images. Sequence diagram for MyImage async download, caching, and fallbacksequenceDiagram
actor WPF as WPFFramework
participant MI as MyImage
participant Disp as Dispatcher
participant Tasks as DownloadTasks
participant Http as HttpRequestBuilder
WPF->>MI: Initialized event
MI->>MI: Load
MI->>Disp: BeginInvoke(async delegate)
activate Disp
Disp->>MI: Async lambda execution
MI->>MI: ActualSource = LoadingSource
MI->>Tasks: GetOrAdd(Url, DownloadImage)
alt New task for Url
Tasks->>MI: Returns new Task for Url
MI->>Http: Create(Url).SendAsync()
Http-->>MI: HttpResponseMessage
MI->>MI: Save stream to temp file
MI->>MI: Move to cache path
MI-->>Tasks: Return temp path
else Existing task for Url
Tasks-->>MI: Existing Task for Url
end
MI->>Tasks: await Task for Url
alt Url download succeeded
MI->>MI: ActualSource = urlTempPath
Disp-->>MI: Async lambda returns
else Url download failed or returned empty
MI->>Tasks: GetOrAdd(FallbackSource, DownloadImage)
alt New task for FallbackSource
Tasks->>MI: Returns new Task for FallbackSource
MI->>Http: Create(FallbackSource).SendAsync()
Http-->>MI: HttpResponseMessage
MI->>MI: Save stream to temp file
MI->>MI: Move to fallback cache path
MI-->>Tasks: Return fallback temp path
else Existing task for FallbackSource
Tasks-->>MI: Existing Task for FallbackSource
end
MI->>Tasks: await Task for FallbackSource
alt Fallback succeeded
MI->>MI: ActualSource = fallbackTempPath
else Fallback failed or returned empty
MI->>MI: Try load from local cache for Url
end
end
Disp-->>WPF: UI updated with ActualSource
Updated class diagram for MyImage, MyBitmap, and MyListItem interactionsclassDiagram
class MyImage {
+CornerRadius CornerRadius
+String Source
+String LoadingSource
+String FallbackSource
+Boolean EnableCache
-String _ActualSource
+String ActualSource
-Shared ConcurrentDictionary~String, Task~String~~ _downloadTasks
+Sub Load()
+Sub UpdateClip()
+Shared Function GetTempPath(Url As String) String
-Shared Async Function DownloadImage(url As String) Task~String~
}
class MyBitmap {
+Sub New()
+Sub LoadFromPath(FilePathOrResourceName As String)
}
class MyListItem {
+String Title
+String Info
+String Logo
+Object Tags
+Object Tag
+Object PathLogo
+Sub New()
}
MyListItem "1" o-- "1" MyImage : PathLogo
MyBitmap ..> MyImage : loads image files for
MyImage ..> ConcurrentDictionary : uses
class ConcurrentDictionary {
+Function GetOrAdd(key As String, valueFactory As Func~String, Task~String~~) Task~String~
+Function Remove(key As String, value As Task~String~) Boolean
}
Flow diagram for DownloadImage temp file handling and cleanupflowchart TD
A[Start DownloadImage url] --> B[Compute tempPath = GetTempPath url]
B --> C[Compute TempDownloadingPath = tempPath + random]
C --> D[CreateDirectory GetPathFromFullPath tempPath]
D --> E[Create FileStream TempDownloadingPath]
E --> F[SendAsync HttpRequestBuilder for url]
F --> G{response.EnsureSuccessStatusCode}
G -->|Success| H[Get response.AsStreamAsync]
H --> I[Copy network stream to FileStream]
I --> J[Dispose streams]
J --> K[File.Move TempDownloadingPath to tempPath]
K --> L[Return tempPath]
G -->|Throws exception| X[Catch Exception]
X --> M{File.Exists tempPath}
M -->|Yes| N[File.Delete tempPath]
M -->|No| O[Skip delete tempPath]
N --> P{File.Exists TempDownloadingPath}
O --> P
P -->|Yes| Q[File.Delete TempDownloadingPath]
P -->|No| R[Skip delete TempDownloadingPath]
Q --> S[Log failure with url and tempPath]
R --> S
S --> T[Return String.Empty]
T --> U[End]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我已经留下了一些整体上的反馈:
- 在
_downloadTasks.GetOrAdd的调用中,ContinueWith移除的是FallbackSource作为键,而不是真正的任务键(例如Url/key),这会导致字典中主 URL 对应的条目无限期保留,并且错误地移除后备任务。 - 在
DownloadImage中,File.Move(TempDownloadingPath, tempPath)不再使用覆盖标志;如果缓存文件已经存在,这里会抛出异常并不必要地触发错误路径,实际上会导致无法刷新已有的缓存图片。
面向 AI 代理的提示词
Please address the comments from this code review:
## Overall Comments
- In the `_downloadTasks.GetOrAdd` calls, the `ContinueWith` removes the `FallbackSource` key instead of the actual task key (e.g., `Url`/`key`), which can leave entries for the primary URL in the dictionary indefinitely and incorrectly remove fallback tasks.
- In `DownloadImage`, `File.Move(TempDownloadingPath, tempPath)` no longer uses the overwrite flag; if a cache file already exists this will throw and trigger the error path unnecessarily, effectively making it impossible to refresh an existing cached image.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- In the
_downloadTasks.GetOrAddcalls, theContinueWithremoves theFallbackSourcekey instead of the actual task key (e.g.,Url/key), which can leave entries for the primary URL in the dictionary indefinitely and incorrectly remove fallback tasks. - In
DownloadImage,File.Move(TempDownloadingPath, tempPath)no longer uses the overwrite flag; if a cache file already exists this will throw and trigger the error path unnecessarily, effectively making it impossible to refresh an existing cached image.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the `_downloadTasks.GetOrAdd` calls, the `ContinueWith` removes the `FallbackSource` key instead of the actual task key (e.g., `Url`/`key`), which can leave entries for the primary URL in the dictionary indefinitely and incorrectly remove fallback tasks.
- In `DownloadImage`, `File.Move(TempDownloadingPath, tempPath)` no longer uses the overwrite flag; if a cache file already exists this will throw and trigger the error path unnecessarily, effectively making it impossible to refresh an existing cached image.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
ruattd
reviewed
Mar 18, 2026
ruattd
approved these changes
Mar 19, 2026
LinQingYuu
approved these changes
Mar 19, 2026
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.
Close #1615
Summary by Sourcery
改进启动器中的图像加载鲁棒性和外观。
Bug 修复:
增强:
Original summary in English
Summary by Sourcery
Improve image loading robustness and appearance across the launcher.
Bug Fixes:
Enhancements: