Skip to content

Commit 857ff73

Browse files
taoocerosjjw24
authored andcommitted
Use IReadOnlyCollection to avoid avoid duplicate iteration
Add distinct to NewResults to try avoiding duplicate result
1 parent b2f841e commit 857ff73

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ public void Save()
748748
/// <summary>
749749
/// To avoid deadlock, this method should not called from main thread
750750
/// </summary>
751-
public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
751+
public void UpdateResultView(IReadOnlyCollection<ResultsForUpdate> resultsForUpdates)
752752
{
753753
if (!resultsForUpdates.Any())
754754
return;

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using System;
1+
using Flow.Launcher.Infrastructure.UserSettings;
2+
using Flow.Launcher.Plugin;
23
using System.Collections.Generic;
3-
using System.Collections.ObjectModel;
44
using System.Collections.Specialized;
55
using System.Linq;
66
using System.Threading;
7-
using System.Threading.Tasks;
87
using System.Windows;
98
using System.Windows.Controls;
109
using System.Windows.Data;
1110
using System.Windows.Documents;
12-
using Flow.Launcher.Infrastructure.UserSettings;
13-
using Flow.Launcher.Plugin;
1411

1512
namespace Flow.Launcher.ViewModel
1613
{
@@ -146,7 +143,7 @@ public void AddResults(List<Result> newRawResults, string resultId)
146143
/// <summary>
147144
/// To avoid deadlock, this method should not called from main thread
148145
/// </summary>
149-
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token)
146+
public void AddResults(IReadOnlyCollection<ResultsForUpdate> resultsForUpdates, CancellationToken token)
150147
{
151148
var newResults = NewResults(resultsForUpdates);
152149

@@ -192,10 +189,11 @@ private List<ResultViewModel> NewResults(List<Result> newRawResults, string resu
192189
return results.Where(r => r.Result.PluginID != resultId)
193190
.Concat(newResults)
194191
.OrderByDescending(r => r.Result.Score)
192+
.Distinct()
195193
.ToList();
196194
}
197195

198-
private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsForUpdates)
196+
private List<ResultViewModel> NewResults(IReadOnlyCollection<ResultsForUpdate> resultsForUpdates)
199197
{
200198
if (!resultsForUpdates.Any())
201199
return Results.ToList();
@@ -205,6 +203,7 @@ private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsFo
205203
return results.Where(r => r != null && !resultsForUpdates.Any(u => u.Metadata.ID == r.Result.PluginID))
206204
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
207205
.OrderByDescending(rv => rv.Result.Score)
206+
.Distinct()
208207
.ToList();
209208
}
210209
#endregion

0 commit comments

Comments
 (0)