Merge pull request #3112 from Flow-Launcher/remove-result-caching

Remove Result Equal used for WPF caching
This commit is contained in:
Jeremy Wu 2025-01-18 21:06:09 +11:00 committed by GitHub
commit 0b8db59e39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 47 deletions

View file

@ -157,27 +157,6 @@ namespace Flow.Launcher.Plugin
} }
} }
/// <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 /> /// <inheritdoc />
public override string ToString() public override string ToString()
{ {

View file

@ -63,28 +63,5 @@ namespace Flow.Launcher.Test.Plugins
}) })
}; };
[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);
}
}
} }
} }

View file

@ -182,7 +182,7 @@ namespace Flow.Launcher.ViewModel
/// <summary> /// <summary>
/// To avoid deadlock, this method should not called from main thread /// To avoid deadlock, this method should not called from main thread
/// </summary> /// </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); var newResults = NewResults(resultsForUpdates);
@ -228,12 +228,12 @@ namespace Flow.Launcher.ViewModel
.ToList(); .ToList();
} }
private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsForUpdates) private List<ResultViewModel> NewResults(ICollection<ResultsForUpdate> resultsForUpdates)
{ {
if (!resultsForUpdates.Any()) if (!resultsForUpdates.Any())
return Results; 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))) .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
.OrderByDescending(rv => rv.Result.Score) .OrderByDescending(rv => rv.Result.Score)
.ToList(); .ToList();