Skip to content

Commit 4dcc279

Browse files
authored
Merge pull request #387 from Flow-Launcher/fix_windowsindex_exclude
Add ConfigureWait and cancellation token
2 parents 647e2b4 + 9479923 commit 4dcc279

File tree

5 files changed

+33
-62
lines changed

5 files changed

+33
-62
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ internal async static Task<List<Result>> ExecuteWindowsIndexSearchAsync(string i
6363
}
6464
}
6565
}
66-
catch (OperationCanceledException)
67-
{
68-
return new List<Result>(); // The source code indicates that without adding members, it won't allocate an array
69-
}
7066
catch (InvalidOperationException e)
7167
{
7268
// Internal error from ExecuteReader(): Connection closed.
@@ -95,12 +91,13 @@ internal async static Task<List<Result>> WindowsIndexSearchAsync(string searchSt
9591
return new List<Result>();
9692

9793
var constructedQuery = constructQuery(searchString);
98-
return await RemoveResultsInExclusionList(
99-
await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token),
100-
exclusionList);
94+
return RemoveResultsInExclusionList(
95+
await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token).ConfigureAwait(false),
96+
exclusionList,
97+
token);
10198
}
10299

103-
private async static Task<List<Result>> RemoveResultsInExclusionList(List<Result> results, List<AccessLink> exclusionList)
100+
private static List<Result> RemoveResultsInExclusionList(List<Result> results, List<AccessLink> exclusionList, CancellationToken token)
104101
{
105102
var indexExclusionListCount = exclusionList.Count;
106103

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

110107
var filteredResults = new List<Result>();
111108

112-
await Task.Run(() =>
109+
for (var index = 0; index < results.Count; index++)
113110
{
114-
for (var index = 0; index < results.Count; index++)
111+
token.ThrowIfCancellationRequested();
112+
113+
var excludeResult = false;
114+
115+
for (var i = 0; i < indexExclusionListCount; i++)
115116
{
116-
var excludeResult = false;
117+
token.ThrowIfCancellationRequested();
117118

118-
for (var i = 0; i < indexExclusionListCount; i++)
119+
if (results[index].SubTitle.StartsWith(exclusionList[i].Path, StringComparison.OrdinalIgnoreCase))
119120
{
120-
if (results[index].SubTitle.StartsWith(exclusionList[i].Path, StringComparison.OrdinalIgnoreCase))
121-
{
122-
excludeResult = true;
123-
break;
124-
}
121+
excludeResult = true;
122+
break;
125123
}
126-
127-
if (!excludeResult)
128-
filteredResults.Add(results[index]);
129124
}
130-
});
125+
126+
if (!excludeResult)
127+
filteredResults.Add(results[index]);
128+
}
131129

132130
return filteredResults;
133131
}

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,21 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
5050
win32 = _win32s;
5151
uwps = _uwps;
5252

53-
try
53+
var result = await Task.Run(delegate
5454
{
55-
var result = await Task.Run(delegate
56-
{
57-
try
58-
{
59-
return win32.Cast<IProgram>()
60-
.Concat(uwps)
61-
.AsParallel()
62-
.WithCancellation(token)
63-
.Where(p => p.Enabled)
64-
.Select(p => p.Result(query.Search, _context.API))
65-
.Where(r => r?.Score > 0)
66-
.ToList();
67-
}
68-
catch (OperationCanceledException)
69-
{
70-
return null;
71-
}
72-
}, token).ConfigureAwait(false);
73-
74-
token.ThrowIfCancellationRequested();
75-
76-
return result;
77-
}
78-
catch (OperationCanceledException)
79-
{
80-
return null;
81-
}
55+
return win32.Cast<IProgram>()
56+
.Concat(uwps)
57+
.AsParallel()
58+
.WithCancellation(token)
59+
.Where(p => p.Enabled)
60+
.Select(p => p.Result(query.Search, _context.API))
61+
.Where(r => r?.Score > 0)
62+
.ToList();
63+
}, token).ConfigureAwait(false);
64+
65+
token.ThrowIfCancellationRequested();
66+
67+
return result;
8268
}
8369

8470
public async Task InitAsync(PluginInitContext context)

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
3030
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
3131
return null;
3232
}
33-
catch (OperationCanceledException)
34-
{
35-
return null;
36-
}
37-
3833

3934
if (string.IsNullOrEmpty(result)) return new List<string>();
4035
Match match = _reg.Match(result);

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
4545
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
4646
return null;
4747
}
48-
catch (OperationCanceledException)
49-
{
50-
return new List<string>();
51-
}
5248
catch (JsonException e)
5349
{
5450
Log.Exception("|Bing.Suggestions|can't parse suggestions", e);

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public override async Task<List<string>> Suggestions(string query, CancellationT
3737
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
3838
return null;
3939
}
40-
catch (OperationCanceledException)
41-
{
42-
return new List<string>();
43-
}
4440
catch (JsonException e)
4541
{
4642
Log.Exception("|Google.Suggestions|can't parse suggestions", e);

0 commit comments

Comments
 (0)