Skip to content

Commit 4debacd

Browse files
Refactor program indexing and cache logic
No longer await on first run (no cache detected) to speed up boost 30 hours cache life
1 parent b123c09 commit 4debacd

File tree

1 file changed

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

1 file changed

+15
-12
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,24 @@ public async Task InitAsync(PluginInitContext context)
8888

8989
bool cacheEmpty = !_win32s.Any() && !_uwps.Any();
9090

91-
var a = Task.Run(() =>
91+
if (cacheEmpty || _settings.LastIndexTime.AddHours(30) < DateTime.Now)
9292
{
93-
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
94-
});
95-
96-
var b = Task.Run(() =>
93+
_ = Task.Run(async () =>
94+
{
95+
await IndexProgramsAsync().ConfigureAwait(false);
96+
WatchProgramUpdate();
97+
});
98+
}
99+
else
97100
{
98-
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|UWPPRogram index cost", IndexUwpPrograms);
99-
});
100-
101-
if (cacheEmpty)
102-
await Task.WhenAll(a, b);
101+
WatchProgramUpdate();
102+
}
103103

104-
Win32.WatchProgramUpdate(_settings);
105-
_ = UWP.WatchPackageChange();
104+
static void WatchProgramUpdate()
105+
{
106+
Win32.WatchProgramUpdate(_settings);
107+
_ = UWP.WatchPackageChange();
108+
}
106109
}
107110

108111
public static void IndexWin32Programs()

0 commit comments

Comments
 (0)