Merge pull request #387 from Flow-Launcher/fix_windowsindex_exclude

Add ConfigureWait and cancellation token
This commit is contained in:
Jeremy Wu 2021-03-18 14:48:18 +11:00 committed by GitHub
commit 4dcc279002
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 60 deletions

View file

@ -63,10 +63,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
}
}
}
catch (OperationCanceledException)
{
return new List<Result>(); // The source code indicates that without adding members, it won't allocate an array
}
catch (InvalidOperationException e)
{
// Internal error from ExecuteReader(): Connection closed.
@ -95,12 +91,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
return new List<Result>();
var constructedQuery = constructQuery(searchString);
return await RemoveResultsInExclusionList(
await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token),
exclusionList);
return RemoveResultsInExclusionList(
await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token).ConfigureAwait(false),
exclusionList,
token);
}
private async static Task<List<Result>> RemoveResultsInExclusionList(List<Result> results, List<AccessLink> exclusionList)
private static List<Result> RemoveResultsInExclusionList(List<Result> results, List<AccessLink> exclusionList, CancellationToken token)
{
var indexExclusionListCount = exclusionList.Count;
@ -109,25 +106,26 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
var filteredResults = new List<Result>();
await Task.Run(() =>
for (var index = 0; index < results.Count; index++)
{
for (var index = 0; index < results.Count; index++)
token.ThrowIfCancellationRequested();
var excludeResult = false;
for (var i = 0; i < indexExclusionListCount; i++)
{
var excludeResult = false;
token.ThrowIfCancellationRequested();
for (var i = 0; i < indexExclusionListCount; i++)
if (results[index].SubTitle.StartsWith(exclusionList[i].Path, StringComparison.OrdinalIgnoreCase))
{
if (results[index].SubTitle.StartsWith(exclusionList[i].Path, StringComparison.OrdinalIgnoreCase))
{
excludeResult = true;
break;
}
excludeResult = true;
break;
}
if (!excludeResult)
filteredResults.Add(results[index]);
}
});
if (!excludeResult)
filteredResults.Add(results[index]);
}
return filteredResults;
}

View file

@ -50,35 +50,21 @@ namespace Flow.Launcher.Plugin.Program
win32 = _win32s;
uwps = _uwps;
try
var result = await Task.Run(delegate
{
var result = await Task.Run(delegate
{
try
{
return win32.Cast<IProgram>()
.Concat(uwps)
.AsParallel()
.WithCancellation(token)
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API))
.Where(r => r?.Score > 0)
.ToList();
}
catch (OperationCanceledException)
{
return null;
}
}, token).ConfigureAwait(false);
return win32.Cast<IProgram>()
.Concat(uwps)
.AsParallel()
.WithCancellation(token)
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API))
.Where(r => r?.Score > 0)
.ToList();
}, token).ConfigureAwait(false);
token.ThrowIfCancellationRequested();
token.ThrowIfCancellationRequested();
return result;
}
catch (OperationCanceledException)
{
return null;
}
return result;
}
public async Task InitAsync(PluginInitContext context)

View file

@ -30,11 +30,6 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return null;
}
catch (OperationCanceledException)
{
return null;
}
if (string.IsNullOrEmpty(result)) return new List<string>();
Match match = _reg.Match(result);

View file

@ -45,10 +45,6 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return null;
}
catch (OperationCanceledException)
{
return new List<string>();
}
catch (JsonException e)
{
Log.Exception("|Bing.Suggestions|can't parse suggestions", e);

View file

@ -37,10 +37,6 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
return null;
}
catch (OperationCanceledException)
{
return new List<string>();
}
catch (JsonException e)
{
Log.Exception("|Google.Suggestions|can't parse suggestions", e);