Refactor caching and indexing logic

Added `ResetCache` calls after clearing `_win32s` and `_uwps` lists to ensure proper cache reset during indexing. Updated logic to return `resultList` after setting cache size and expiration for improved clarity. Removed `await Task.WhenAll` to adjust asynchronous flow in the indexing process.
This commit is contained in:
Jack251970 2025-11-06 15:29:38 +08:00
parent 3d8fd1d352
commit 7e332fa615

View file

@ -142,7 +142,7 @@ namespace Flow.Launcher.Plugin.Program
entry.SetSize(resultList.Count); entry.SetSize(resultList.Count);
entry.SetSlidingExpiration(TimeSpan.FromHours(8)); entry.SetSlidingExpiration(TimeSpan.FromHours(8));
return resultList; return resultList;
}); });
@ -335,6 +335,7 @@ namespace Flow.Launcher.Plugin.Program
{ {
_win32s.Add(win32); _win32s.Add(win32);
} }
ResetCache();
await Context.API.SaveCacheBinaryStorageAsync<List<Win32>>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath); await Context.API.SaveCacheBinaryStorageAsync<List<Win32>>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
lock (_lastIndexTimeLock) lock (_lastIndexTimeLock)
{ {
@ -364,6 +365,7 @@ namespace Flow.Launcher.Plugin.Program
{ {
_uwps.Add(uwp); _uwps.Add(uwp);
} }
ResetCache();
await Context.API.SaveCacheBinaryStorageAsync<List<UWPApp>>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath); await Context.API.SaveCacheBinaryStorageAsync<List<UWPApp>>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
lock (_lastIndexTimeLock) lock (_lastIndexTimeLock)
{ {
@ -393,7 +395,6 @@ namespace Flow.Launcher.Plugin.Program
}); });
Context.API.LogDebug(ClassName, "Start indexing"); Context.API.LogDebug(ClassName, "Start indexing");
await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false); await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false);
} }