-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Optimize #8862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize #8862
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -248,6 +248,24 @@ public async Task<Dictionary<string, ProfileItem>> GetProfileItemsByIndexIdsAsMa | |||||
| return items.ToDictionary(it => it.IndexId); | ||||||
| } | ||||||
|
|
||||||
| public async Task<List<ProfileItem>> GetProfileItemsOrderedByIndexIds(IEnumerable<string> indexIds) | ||||||
| { | ||||||
| var idList = indexIds.Where(id => !id.IsNullOrEmpty()).Distinct().ToList(); | ||||||
| if (idList.Count == 0) | ||||||
| { | ||||||
| return []; | ||||||
| } | ||||||
|
|
||||||
| var items = await SQLiteHelper.Instance.TableAsync<ProfileItem>() | ||||||
| .Where(it => idList.Contains(it.IndexId)) | ||||||
| .ToListAsync(); | ||||||
| var itemMap = items.ToDictionary(it => it.IndexId); | ||||||
|
|
||||||
| return idList.Select(id => itemMap.GetValueOrDefault(id)) | ||||||
| .Where(item => item != null) | ||||||
|
||||||
| .Where(item => item != null) | |
| .OfType<ProfileItem>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个刚开始的写法就是 .OfType<ProfileItem>() 来着,ReSharper 直接冒绿光让我改成 .Where(item => item != null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按编辑器的提示吧。 ai 有时候会弄过时的方案
Copilot
AI
Mar 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetProfileItemsOrderedByIndexIds calls Distinct() on the incoming indexIds, which removes duplicate ids. Previously, call sites that built ordered lists (e.g., group ChildItems ordering) would preserve duplicates by iterating the original id list. If duplicates are meaningful (e.g., weighting / repeated nodes), this changes behavior; consider keeping the original idList for ordering and using a separate distinct set only for the DB query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边就不去重了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去重应该更合理些
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但是是否存在一个可能,用户是故意添加的重复的呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那就不改了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
并且这玩意也不是严格对应的,会跳过某些无效项,也不应该直接下标访问,注释没写
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但是是否存在一个可能,用户是故意添加的重复的呢?
先不管了吧,重复的没什么意义,有人说了再改吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method signature takes
IEnumerable<string> indexIds, but several new call sites passSelect(sp => sp?.IndexId)which is naturally anIEnumerable<string?>and can contain nulls. Since the implementation already filters out null/empty ids, consider changing the parameter type toIEnumerable<string?>(or accepting nullable and guarding) to better reflect actual usage and avoid nullability mismatches.