Skip to content

Commit 86edae2

Browse files
committed
Use Generic to remove duplicate query
1 parent 24ce101 commit 86edae2

File tree

1 file changed

+15
-21
lines changed
  • Plugins/Flow.Launcher.Plugin.Program

1 file changed

+15
-21
lines changed

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,17 @@ public List<Result> Query(Query query)
7171
Win32[] win32;
7272
UWP.Application[] uwps;
7373

74-
lock (IndexLock)
75-
{ // just take the reference inside the lock to eliminate query time issues.
76-
win32 = _win32s;
77-
uwps = _uwps;
78-
}
79-
80-
var results1 = win32.AsParallel()
81-
.Where(p => p.Enabled)
82-
.Select(p => p.Result(query.Search, _context.API));
74+
win32 = _win32s;
75+
uwps = _uwps;
8376

84-
var results2 = uwps.AsParallel()
85-
.Where(p => p.Enabled)
86-
.Select(p => p.Result(query.Search, _context.API));
77+
var result = win32.Cast<IProgram>()
78+
.Concat(uwps)
79+
.AsParallel()
80+
.Where(p => p.Enabled)
81+
.Select(p => p.Result(query.Search, _context.API))
82+
.Where(r => r?.Score > 0)
83+
.ToList();
8784

88-
var result = results1.Concat(results2).Where(r => r != null && r.Score > 0).ToList();
8985
return result;
9086
}
9187

@@ -97,10 +93,9 @@ public void Init(PluginInitContext context)
9793
public static void IndexWin32Programs()
9894
{
9995
var win32S = Win32.All(_settings);
100-
lock (IndexLock)
101-
{
102-
_win32s = win32S;
103-
}
96+
97+
_win32s = win32S;
98+
10499
}
105100

106101
public static void IndexUWPPrograms()
@@ -109,10 +104,9 @@ public static void IndexUWPPrograms()
109104
var support = Environment.OSVersion.Version.Major >= windows10.Major;
110105

111106
var applications = support ? UWP.All() : new UWP.Application[] { };
112-
lock (IndexLock)
113-
{
114-
_uwps = applications;
115-
}
107+
108+
_uwps = applications;
109+
116110
}
117111

118112
public static void IndexPrograms()

0 commit comments

Comments
 (0)