Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ internal async static Task<List<Result>> ExecuteWindowsIndexSearchAsync(string i
}
}
}
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.
Expand Down Expand Up @@ -95,12 +91,13 @@ internal async static Task<List<Result>> WindowsIndexSearchAsync(string searchSt
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;

Expand All @@ -109,25 +106,26 @@ private async static Task<List<Result>> RemoveResultsInExclusionList(List<Result

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;
}
Expand Down
42 changes: 14 additions & 28 deletions Plugins/Flow.Launcher.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,21 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
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);

token.ThrowIfCancellationRequested();

return result;
}
catch (OperationCanceledException)
{
return null;
}
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();

return result;
}

public async Task InitAsync(PluginInitContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
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);
Expand Down