Skip to content

Commit 2941e03

Browse files
committed
add logging and method summaries
1 parent b4955f7 commit 2941e03

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,11 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13411341
if (currentIsHomeQuery)
13421342
{
13431343
if (ShouldClearExistingResultsForNonQuery(plugins))
1344+
{
13441345
Results.Clear();
1346+
App.API.LogDebug(ClassName, $"Existing results are cleared for non-query");
1347+
}
1348+
13451349

13461350
tasks = plugins.Select(plugin => plugin.Metadata.HomeDisabled switch
13471351
{
@@ -1548,7 +1552,9 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
15481552

15491553
/// <summary>
15501554
/// Determines whether the existing search results should be cleared based on the current query and the previous query type.
1551-
/// This is needed because of the design that treats plugins with action keywords and global action keywords separately. Results are gathered
1555+
/// This is used to indicate to QueryTaskAsync or QueryHistoryTask whether to clear results. If both QueryTaskAsync and QueryHistoryTask
1556+
/// are not called then use ShouldClearExistingResultsForNonQuery instead.
1557+
/// This method needed because of the design that treats plugins with action keywords and global action keywords separately. Results are gathered
15521558
/// either from plugins with matching action keywords or global action keyword, but not both. So when the current results are from plugins
15531559
/// with a matching action keyword and a new result set comes from a new query with the global action keyword, the existing results need to be cleared,
15541560
/// and vice versa. The same applies to home page query results.
@@ -1564,25 +1570,34 @@ private bool ShouldClearExistingResultsForQuery(Query query, bool currentIsHomeQ
15641570
// If previous or current results are from home query, we need to clear them
15651571
if (_previousIsHomeQuery || currentIsHomeQuery)
15661572
{
1567-
App.API.LogDebug(ClassName, $"Cleared old results");
1573+
App.API.LogDebug(ClassName, $"Existing results should be cleared for query");
15681574
return true;
15691575
}
15701576

15711577
// If the last and current query are not home query type, we need to check the action keyword
15721578
if (_lastQuery?.ActionKeyword != query?.ActionKeyword)
15731579
{
1574-
App.API.LogDebug(ClassName, $"Cleared old results");
1580+
App.API.LogDebug(ClassName, $"Existing results should be cleared for query");
15751581
return true;
15761582
}
15771583

15781584
return false;
15791585
}
15801586

1587+
/// <summary>
1588+
/// Determines whether existing results should be cleared for non-query calls.
1589+
/// A non-query call is where QueryTaskAsync and QueryHistoryTask methods are both not called.
1590+
/// QueryTaskAsync and QueryHistoryTask both handle result updating (clearing if required) so directly calling
1591+
/// Results.Clear() is not required. However when both are not called, we need to directly clear results and this
1592+
/// method determines on the condition when clear results should happen.
1593+
/// </summary>
1594+
/// <param name="plugins">The collection of plugins to check.</param>
1595+
/// <returns>True if existing results should be cleared, false otherwise.</returns>
15811596
private bool ShouldClearExistingResultsForNonQuery(ICollection<PluginPair> plugins)
15821597
{
15831598
if (!Settings.ShowHistoryResultsForHomePage && (plugins.Count == 0 || plugins.All(x => x.Metadata.HomeDisabled == true)))
15841599
{
1585-
App.API.LogDebug(ClassName, $"Cleared old results");
1600+
App.API.LogDebug(ClassName, $"Existing results should be cleared for non-query");
15861601
return true;
15871602
}
15881603

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ private List<ResultViewModel> NewResults(ICollection<ResultsForUpdate> resultsFo
235235
var newResults = resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings));
236236

237237
if (resultsForUpdates.Any(x => x.shouldClearExistingResults))
238+
{
239+
App.API.LogDebug("NewResults", $"Existing results are cleared for query");
238240
return newResults.OrderByDescending(rv => rv.Result.Score).ToList();
241+
}
239242

240243
return Results.Where(r => r?.Result != null && resultsForUpdates.All(u => u.ID != r.Result.PluginID))
241244
.Concat(newResults)

0 commit comments

Comments
 (0)