From 3eebae76f2450c9c0a605660f2f8caecf8b0428e Mon Sep 17 00:00:00 2001 From: Marco Gavelli Date: Thu, 25 Mar 2021 00:28:59 +0100 Subject: [PATCH] Tweak cache loading --- .../FileListCache/FileListCacheController.cs | 4 ++-- Files/ViewModels/ItemViewModel.cs | 23 ++++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Files/Helpers/FileListCache/FileListCacheController.cs b/Files/Helpers/FileListCache/FileListCacheController.cs index 93a04422b4eb..1c8ae8472aa3 100644 --- a/Files/Helpers/FileListCache/FileListCacheController.cs +++ b/Files/Helpers/FileListCache/FileListCacheController.cs @@ -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 }); diff --git a/Files/ViewModels/ItemViewModel.cs b/Files/ViewModels/ItemViewModel.cs index ff98a7c79648..9812e067f7c1 100644 --- a/Files/ViewModels/ItemViewModel.cs +++ b/Files/ViewModels/ItemViewModel.cs @@ -869,20 +869,11 @@ 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) { @@ -890,13 +881,7 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi } 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(); @@ -905,6 +890,8 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi }); if (cacheResult != null) { + await OrderFilesAndFoldersAsync(); + await ApplyFilesAndFoldersChangesAsync(); IsLoadingItems = false; } }