Skip to content

Commit

Permalink
Merge pull request #3112 from Flow-Launcher/remove-result-caching
Browse files Browse the repository at this point in the history
Remove Result Equal used for WPF caching
  • Loading branch information
jjw24 authored Jan 18, 2025
2 parents 484578d + 8e5d778 commit 0b8db59
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 47 deletions.
21 changes: 0 additions & 21 deletions Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,6 @@ public string PluginDirectory
}
}

/// <inheritdoc />
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;
}

/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine(Title, SubTitle, AutoCompleteText, CopyText, IcoPath);
}

/// <inheritdoc />
public override string ToString()
{
Expand Down
23 changes: 0 additions & 23 deletions Flow.Launcher.Test/Plugins/JsonRPCPluginTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, result2);
Assert.AreEqual(result1, referenceResult);

Assert.IsNotNull(result1);
Assert.IsNotNull(result1.AsyncAction);
}
}

}
}
6 changes: 3 additions & 3 deletions Flow.Launcher/ViewModel/ResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void AddResults(List<Result> newRawResults, string resultId)
/// <summary>
/// To avoid deadlock, this method should not called from main thread
/// </summary>
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
public void AddResults(ICollection<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
{
var newResults = NewResults(resultsForUpdates);

Expand Down Expand Up @@ -228,12 +228,12 @@ private List<ResultViewModel> NewResults(List<Result> newRawResults, string resu
.ToList();
}

private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsForUpdates)
private List<ResultViewModel> NewResults(ICollection<ResultsForUpdate> 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?.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();
Expand Down

0 comments on commit 0b8db59

Please sign in to comment.