From 41a345a70006e881709b1c6543e683926289b583 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Fri, 6 Dec 2024 23:55:20 -0600 Subject: [PATCH 1/5] Remove Result comparison and Change signature from IEnumerable to ICollection (due to the potential of multiple enumeration) --- Flow.Launcher.Plugin/Result.cs | 21 --------------------- Flow.Launcher/ViewModel/ResultsViewModel.cs | 6 +++--- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index 9b42b102176..ac0b827c02f 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -156,27 +156,6 @@ public string PluginDirectory } } - /// - public override bool Equals(object obj) - { - var r = obj as Result; - - var equality = string.Equals(r?.Title, Title) && - string.Equals(r?.SubTitle, SubTitle) && - string.Equals(r?.AutoCompleteText, AutoCompleteText) && - string.Equals(r?.CopyText, CopyText) && - string.Equals(r?.IcoPath, IcoPath) && - TitleHighlightData == r.TitleHighlightData; - - return equality; - } - - /// - public override int GetHashCode() - { - return HashCode.Combine(Title, SubTitle, AutoCompleteText, CopyText, IcoPath); - } - /// public override string ToString() { diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 107372e0115..c0e0b146d03 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -182,7 +182,7 @@ public void AddResults(List newRawResults, string resultId) /// /// To avoid deadlock, this method should not called from main thread /// - public void AddResults(IEnumerable resultsForUpdates, CancellationToken token, bool reselect = true) + public void AddResults(ICollection resultsForUpdates, CancellationToken token, bool reselect = true) { var newResults = NewResults(resultsForUpdates); @@ -228,12 +228,12 @@ private List NewResults(List newRawResults, string resu .ToList(); } - private List NewResults(IEnumerable resultsForUpdates) + private List NewResults(ICollection resultsForUpdates) { if (!resultsForUpdates.Any()) return Results; - return Results.Where(r => r != null && !resultsForUpdates.Any(u => u.ID == r.Result.PluginID)) + return Results.Where(r => r != null && resultsForUpdates.All(u => u.ID != r.Result.PluginID)) .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings))) .OrderByDescending(rv => rv.Result.Score) .ToList(); From 51a16cc40f8159f6e54d772df16e5ae0466be989 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Fri, 6 Dec 2024 23:55:20 -0600 Subject: [PATCH 2/5] Remove Result comparison and Change signature from IEnumerable to ICollection (due to the potential of multiple enumeration) --- Flow.Launcher.Plugin/Result.cs | 21 --------------------- Flow.Launcher/ViewModel/ResultsViewModel.cs | 6 +++--- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index f2050cc9f78..c6ca81cf31c 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -157,27 +157,6 @@ public string PluginDirectory } } - /// - public override bool Equals(object obj) - { - var r = obj as Result; - - var equality = string.Equals(r?.Title, Title) && - string.Equals(r?.SubTitle, SubTitle) && - string.Equals(r?.AutoCompleteText, AutoCompleteText) && - string.Equals(r?.CopyText, CopyText) && - string.Equals(r?.IcoPath, IcoPath) && - TitleHighlightData == r.TitleHighlightData; - - return equality; - } - - /// - public override int GetHashCode() - { - return HashCode.Combine(Title, SubTitle, AutoCompleteText, CopyText, IcoPath); - } - /// public override string ToString() { diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 107372e0115..c0e0b146d03 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -182,7 +182,7 @@ public void AddResults(List newRawResults, string resultId) /// /// To avoid deadlock, this method should not called from main thread /// - public void AddResults(IEnumerable resultsForUpdates, CancellationToken token, bool reselect = true) + public void AddResults(ICollection resultsForUpdates, CancellationToken token, bool reselect = true) { var newResults = NewResults(resultsForUpdates); @@ -228,12 +228,12 @@ private List NewResults(List newRawResults, string resu .ToList(); } - private List NewResults(IEnumerable resultsForUpdates) + private List NewResults(ICollection resultsForUpdates) { if (!resultsForUpdates.Any()) return Results; - return Results.Where(r => r != null && !resultsForUpdates.Any(u => u.ID == r.Result.PluginID)) + return Results.Where(r => r != null && resultsForUpdates.All(u => u.ID != r.Result.PluginID)) .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings))) .OrderByDescending(rv => rv.Result.Score) .ToList(); From 5f6ac6a35e38c301ffb2b8b2fdc5af95869b3703 Mon Sep 17 00:00:00 2001 From: Kevin Zhang <45326534+taooceros@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:48:15 -0600 Subject: [PATCH 3/5] Update Flow.Launcher/ViewModel/ResultsViewModel.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- Flow.Launcher/ViewModel/ResultsViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index c0e0b146d03..7d2b5bc9348 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -233,7 +233,7 @@ private List NewResults(ICollection resultsFo if (!resultsForUpdates.Any()) return Results; - return Results.Where(r => r != null && resultsForUpdates.All(u => u.ID != r.Result.PluginID)) + return Results.Where(r => r?.Result != null && resultsForUpdates.All(u => u.ID != r.Result.PluginID)) .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings))) .OrderByDescending(rv => rv.Result.Score) .ToList(); From 2de63f73a5bb3eb64a61a04ab190b39ab466d2f5 Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Fri, 10 Jan 2025 13:36:09 -0600 Subject: [PATCH 4/5] change equality related testing --- Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs b/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs index 3d05e56796f..b4e0736c6c2 100644 --- a/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs +++ b/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs @@ -78,8 +78,8 @@ public async Task GivenModel_WhenSerializeWithDifferentNamingPolicy_ThenExpectSa foreach (var ((result1, result2), referenceResult) in results1.Zip(results2).Zip(reference.Result)) { - Assert.AreEqual(result1, result2); - Assert.AreEqual(result1, referenceResult); + Assert.AreEqual(result1.Title, result2.Title); + Assert.AreEqual(result1.Title, referenceResult.Title); Assert.IsNotNull(result1); Assert.IsNotNull(result1.AsyncAction); From 8e5d77878af93e42de831b505a6c926e271917c0 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sat, 18 Jan 2025 20:51:06 +1100 Subject: [PATCH 5/5] remove equality test --- .../Plugins/JsonRPCPluginTest.cs | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs b/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs index b4e0736c6c2..42a4630fe5c 100644 --- a/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs +++ b/Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs @@ -63,28 +63,5 @@ public async Task GivenVariousJsonText_WhenVariousNamingCase_ThenExpectNotNullRe }) }; - [TestCaseSource(typeof(JsonRPCPluginTest), nameof(ResponseModelsSource))] - public async Task GivenModel_WhenSerializeWithDifferentNamingPolicy_ThenExpectSameResult_Async(JsonRPCQueryResponseModel reference) - { - var camelText = JsonSerializer.Serialize(reference, new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); - - var pascalText = JsonSerializer.Serialize(reference); - - var results1 = await QueryAsync(new Query { Search = camelText }, default); - var results2 = await QueryAsync(new Query { Search = pascalText }, default); - - Assert.IsNotNull(results1); - Assert.IsNotNull(results2); - - foreach (var ((result1, result2), referenceResult) in results1.Zip(results2).Zip(reference.Result)) - { - Assert.AreEqual(result1.Title, result2.Title); - Assert.AreEqual(result1.Title, referenceResult.Title); - - Assert.IsNotNull(result1); - Assert.IsNotNull(result1.AsyncAction); - } - } - } }