Skip to content

Commit

Permalink
Tweak cache loading
Browse files Browse the repository at this point in the history
  • Loading branch information
gave92 committed Mar 24, 2021
1 parent 6a471e7 commit 3eebae7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Files/Helpers/FileListCache/FileListCacheController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public Task SaveFileDisplayNameToCache(string path, string displayName)
{
if (displayName == null)
{
filesCache.Remove(path);
fileNamesCache.Remove(path);
return persistentAdapter.SaveFileDisplayNameToCache(path, displayName);
}
filesCache.Set(path, displayName, new MemoryCacheEntryOptions
fileNamesCache.Set(path, displayName, new MemoryCacheEntryOptions
{
Size = 1
});
Expand Down
23 changes: 5 additions & 18 deletions Files/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,34 +869,19 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi
{
cacheResult = await Task.Run(async () =>
{
var sampler = new IntervalSampler(500);
CacheEntry cacheEntry;
try
{
cacheEntry = await fileListCache.ReadFileListFromCache(path, addFilesCTS.Token);
}
catch
{
cacheEntry = null;
}
CacheEntry cacheEntry = await fileListCache.ReadFileListFromCache(path, addFilesCTS.Token);

if (cacheEntry != null)
{
for (var i = 0; i < cacheEntry.FileList.Count; i++)
for (var i = 0; i <= Math.Min(32, cacheEntry.FileList.Count - 1); i++)
{
if (!cacheEntry.FileList[i].IsHiddenItem || AppSettings.AreHiddenItemsVisible)
{
filesAndFolders.Add(cacheEntry.FileList[i]);
}
if (addFilesCTS.IsCancellationRequested)
{
break;
}

if (i == 32 || i == cacheEntry.FileList.Count - 1 || sampler.CheckNow())
{
await OrderFilesAndFoldersAsync();
await ApplyFilesAndFoldersChangesAsync();
return null;
}
}
return filesAndFolders.Select(i => i.ItemPath).ToList();
Expand All @@ -905,6 +890,8 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi
});
if (cacheResult != null)
{
await OrderFilesAndFoldersAsync();
await ApplyFilesAndFoldersChangesAsync();
IsLoadingItems = false;
}
}
Expand Down

0 comments on commit 3eebae7

Please sign in to comment.