Skip to content

Commit 7f4b83e

Browse files
committed
Remvoe caching feature
1 parent 6e1f996 commit 7f4b83e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+231
-993
lines changed

Files/Files.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@
223223
<Compile Include="Helpers\CollectionDebugView.cs" />
224224
<Compile Include="Helpers\DynamicDialogFactory.cs" />
225225
<Compile Include="Helpers\Extension.cs" />
226-
<Compile Include="Helpers\FileListCache\CacheEntry.cs" />
227226
<Compile Include="Helpers\FileListCache\FileListCacheController.cs" />
228227
<Compile Include="Helpers\FileListCache\IFileListCache.cs" />
229228
<Compile Include="Helpers\FileListCache\PersistentSQLiteCacheAdapter.cs" />

Files/Filesystem/StorageEnumerators/UniversalStorageEnumerator.cs

+2-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public static async Task<List<ListedItem>> ListEntries(
2323
string returnformat,
2424
Type sourcePageType,
2525
CancellationToken cancellationToken,
26-
List<string> skipItems,
2726
int countLimit,
2827
Func<List<ListedItem>, Task> intermediateAction
2928
)
@@ -74,14 +73,7 @@ ex is UnauthorizedAccessException
7473
var folder = await AddFolderAsync(item as StorageFolder, currentStorageFolder, returnformat, cancellationToken);
7574
if (folder != null)
7675
{
77-
if (skipItems?.Contains(folder.ItemPath) ?? false)
78-
{
79-
skipItems.Remove(folder.ItemPath);
80-
}
81-
else
82-
{
83-
tempList.Add(folder);
84-
}
76+
tempList.Add(folder);
8577
}
8678
}
8779
else
@@ -90,14 +82,7 @@ ex is UnauthorizedAccessException
9082
var fileEntry = await AddFileAsync(file, currentStorageFolder, returnformat, true, sourcePageType, cancellationToken);
9183
if (fileEntry != null)
9284
{
93-
if (skipItems?.Contains(fileEntry.ItemPath) ?? false)
94-
{
95-
skipItems.Remove(fileEntry.ItemPath);
96-
}
97-
else
98-
{
99-
tempList.Add(fileEntry);
100-
}
85+
tempList.Add(fileEntry);
10186
}
10287
}
10388
if (cancellationToken.IsCancellationRequested)

Files/Filesystem/StorageEnumerators/Win32StorageEnumerator.cs

+2-17
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public static async Task<List<ListedItem>> ListEntries(
2828
WIN32_FIND_DATA findData,
2929
NamedPipeAsAppServiceConnection connection,
3030
CancellationToken cancellationToken,
31-
List<string> skipItems,
3231
int countLimit,
3332
Func<List<ListedItem>, Task> intermediateAction
3433
)
@@ -49,14 +48,7 @@ Func<List<ListedItem>, Task> intermediateAction
4948
var file = await GetFile(findData, path, returnformat, connection, cancellationToken);
5049
if (file != null)
5150
{
52-
if (skipItems?.Contains(file.ItemPath) ?? false)
53-
{
54-
skipItems.Remove(file.ItemPath);
55-
}
56-
else
57-
{
58-
tempList.Add(file);
59-
}
51+
tempList.Add(file);
6052
++count;
6153
}
6254
}
@@ -67,14 +59,7 @@ Func<List<ListedItem>, Task> intermediateAction
6759
var folder = await GetFolder(findData, path, returnformat, cancellationToken);
6860
if (folder != null)
6961
{
70-
if (skipItems?.Contains(folder.ItemPath) ?? false)
71-
{
72-
skipItems.Remove(folder.ItemPath);
73-
}
74-
else
75-
{
76-
tempList.Add(folder);
77-
}
62+
tempList.Add(folder);
7863
++count;
7964
}
8065
}

Files/Helpers/FileListCache/CacheEntry.cs

-11
This file was deleted.

Files/Helpers/FileListCache/FileListCacheController.cs

+2-50
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,11 @@ private FileListCacheController()
2020
persistentAdapter = new PersistentSQLiteCacheAdapter();
2121
}
2222

23-
private readonly IMemoryCache filesCache = new MemoryCache(new MemoryCacheOptions
24-
{
25-
SizeLimit = 1_000_000
26-
});
27-
2823
private readonly IMemoryCache fileNamesCache = new MemoryCache(new MemoryCacheOptions
2924
{
3025
SizeLimit = 1_000_000
3126
});
3227

33-
public Task SaveFileListToCache(string path, CacheEntry cacheEntry)
34-
{
35-
if (!App.AppSettings.UseFileListCache)
36-
{
37-
return Task.CompletedTask;
38-
}
39-
40-
if (cacheEntry == null)
41-
{
42-
filesCache.Remove(path);
43-
return persistentAdapter.SaveFileListToCache(path, cacheEntry);
44-
}
45-
filesCache.Set(path, cacheEntry, new MemoryCacheEntryOptions
46-
{
47-
Size = cacheEntry.FileList.Count
48-
});
49-
50-
// save entry to persistent cache in background
51-
return persistentAdapter.SaveFileListToCache(path, cacheEntry);
52-
}
53-
54-
public async Task<CacheEntry> ReadFileListFromCache(string path, CancellationToken cancellationToken)
55-
{
56-
if (!App.AppSettings.UseFileListCache)
57-
{
58-
return null;
59-
}
60-
61-
var entry = filesCache.Get<CacheEntry>(path);
62-
if (entry == null)
63-
{
64-
entry = await persistentAdapter.ReadFileListFromCache(path, cancellationToken);
65-
if (entry?.FileList != null)
66-
{
67-
filesCache.Set(path, entry, new MemoryCacheEntryOptions
68-
{
69-
Size = entry.FileList.Count
70-
});
71-
}
72-
}
73-
return entry;
74-
}
75-
7628
public async Task<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken)
7729
{
7830
var displayName = fileNamesCache.Get<string>(path);
@@ -94,10 +46,10 @@ public Task SaveFileDisplayNameToCache(string path, string displayName)
9446
{
9547
if (displayName == null)
9648
{
97-
filesCache.Remove(path);
49+
fileNamesCache.Remove(path);
9850
return persistentAdapter.SaveFileDisplayNameToCache(path, displayName);
9951
}
100-
filesCache.Set(path, displayName, new MemoryCacheEntryOptions
52+
fileNamesCache.Set(path, displayName, new MemoryCacheEntryOptions
10153
{
10254
Size = 1
10355
});

Files/Helpers/FileListCache/IFileListCache.cs

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ namespace Files.Helpers.FileListCache
55
{
66
internal interface IFileListCache
77
{
8-
public Task<CacheEntry> ReadFileListFromCache(string path, CancellationToken cancellationToken);
9-
10-
public Task SaveFileListToCache(string path, CacheEntry cacheEntry);
11-
128
public Task<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken);
139

1410
public Task SaveFileDisplayNameToCache(string path, string displayName);

Files/Helpers/FileListCache/PersistentSQLiteCacheAdapter.cs

-118
Original file line numberDiff line numberDiff line change
@@ -15,98 +15,6 @@ internal class PersistentSQLiteCacheAdapter : IFileListCache, IDisposable
1515
private SqliteConnection connection;
1616
private bool disposedValue;
1717

18-
public async Task SaveFileListToCache(string path, CacheEntry cacheEntry)
19-
{
20-
if (!await InitializeIfNeeded())
21-
{
22-
return;
23-
}
24-
const int maxCachedEntries = 128;
25-
try
26-
{
27-
if (cacheEntry == null)
28-
{
29-
using var deleteCommand = new SqliteCommand("DELETE FROM FileListCache WHERE Id = @Id", connection);
30-
deleteCommand.Parameters.Add("@Id", SqliteType.Text).Value = path;
31-
await deleteCommand.ExecuteNonQueryAsync();
32-
return;
33-
}
34-
35-
if (cacheEntry.FileList.Count > maxCachedEntries)
36-
{
37-
cacheEntry.FileList = cacheEntry.FileList.Take(maxCachedEntries).ToList();
38-
}
39-
40-
using var cmd = new SqliteCommand("SELECT Id FROM FileListCache WHERE Id = @Id", connection);
41-
cmd.Parameters.Add("@Id", SqliteType.Text).Value = path;
42-
using var reader = await cmd.ExecuteReaderAsync();
43-
if (reader.HasRows)
44-
{
45-
// need to update entry
46-
using var updateCommand = new SqliteCommand("UPDATE FileListCache SET Timestamp = @Timestamp, Entry = @Entry WHERE Id = @Id", connection);
47-
updateCommand.Parameters.Add("@Id", SqliteType.Text).Value = path;
48-
updateCommand.Parameters.Add("@Timestamp", SqliteType.Integer).Value = GetTimestamp(DateTime.UtcNow);
49-
var settings = new JsonSerializerSettings
50-
{
51-
TypeNameHandling = TypeNameHandling.Auto
52-
};
53-
updateCommand.Parameters.Add("@Entry", SqliteType.Text).Value = JsonConvert.SerializeObject(cacheEntry, settings);
54-
await updateCommand.ExecuteNonQueryAsync();
55-
}
56-
else
57-
{
58-
// need to insert entry
59-
using var insertCommand = new SqliteCommand("INSERT INTO FileListCache (Id, Timestamp, Entry) VALUES (@Id, @Timestamp, @Entry)", connection);
60-
insertCommand.Parameters.Add("@Id", SqliteType.Text).Value = path;
61-
insertCommand.Parameters.Add("@Timestamp", SqliteType.Integer).Value = GetTimestamp(DateTime.UtcNow);
62-
var settings = new JsonSerializerSettings
63-
{
64-
TypeNameHandling = TypeNameHandling.Auto
65-
};
66-
insertCommand.Parameters.Add("@Entry", SqliteType.Text).Value = JsonConvert.SerializeObject(cacheEntry, settings);
67-
await insertCommand.ExecuteNonQueryAsync();
68-
}
69-
}
70-
catch (Exception ex)
71-
{
72-
NLog.LogManager.GetCurrentClassLogger().Warn(ex, ex.Message);
73-
}
74-
}
75-
76-
public async Task<CacheEntry> ReadFileListFromCache(string path, CancellationToken cancellationToken)
77-
{
78-
if (!await InitializeIfNeeded())
79-
{
80-
return null;
81-
}
82-
try
83-
{
84-
using var cmd = new SqliteCommand("SELECT Timestamp, Entry FROM FileListCache WHERE Id = @Id", connection);
85-
cmd.Parameters.Add("@Id", SqliteType.Text).Value = path;
86-
87-
using var reader = await cmd.ExecuteReaderAsync(cancellationToken);
88-
if (!await reader.ReadAsync())
89-
{
90-
return null;
91-
}
92-
var timestamp = reader.GetInt64(0);
93-
var entryAsJson = reader.GetString(1);
94-
var settings = new JsonSerializerSettings
95-
{
96-
TypeNameHandling = TypeNameHandling.Auto
97-
};
98-
var entry = JsonConvert.DeserializeObject<CacheEntry>(entryAsJson, settings);
99-
entry.CurrentFolder.ItemPropertiesInitialized = false;
100-
entry.FileList.ForEach((item) => item.ItemPropertiesInitialized = false);
101-
return entry;
102-
}
103-
catch (Exception ex)
104-
{
105-
NLog.LogManager.GetCurrentClassLogger().Warn(ex, ex.Message);
106-
return null;
107-
}
108-
}
109-
11018
public async Task SaveFileDisplayNameToCache(string path, string displayName)
11119
{
11220
if (!await InitializeIfNeeded())
@@ -190,23 +98,6 @@ public void Dispose()
19098

19199
private void RunCleanupRoutine()
192100
{
193-
Task.Run(async () =>
194-
{
195-
try
196-
{
197-
// remove entries that are 1 month old (timestamp is updated every time the cache is set)
198-
var limitTimestamp = GetTimestamp(DateTime.Now.AddMonths(-1));
199-
using var cmd = new SqliteCommand("DELETE FROM FileListCache WHERE Timestamp < @Timestamp", connection);
200-
cmd.Parameters.Add("@Timestamp", SqliteType.Integer).Value = limitTimestamp;
201-
202-
var count = await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
203-
Debug.WriteLine($"Removed {count} old entries from cache database");
204-
}
205-
catch (Exception ex)
206-
{
207-
NLog.LogManager.GetCurrentClassLogger().Warn(ex, ex.Message);
208-
}
209-
});
210101
}
211102

212103
private async Task<bool> InitializeIfNeeded()
@@ -227,15 +118,6 @@ private async Task<bool> InitializeIfNeeded()
227118
connection.Open();
228119

229120
// create db schema
230-
var createFileListCacheTable = @"CREATE TABLE IF NOT EXISTS ""FileListCache"" (
231-
""Id"" VARCHAR(5000) NOT NULL,
232-
""Timestamp"" INTEGER NOT NULL,
233-
""Entry"" TEXT NOT NULL,
234-
PRIMARY KEY(""Id"")
235-
)";
236-
using var cmdFileListCacheTable = new SqliteCommand(createFileListCacheTable, connection);
237-
cmdFileListCacheTable.ExecuteNonQuery();
238-
239121
var createFileDisplayNameCacheTable = @"CREATE TABLE IF NOT EXISTS ""FileDisplayNameCache"" (
240122
""Id"" VARCHAR(5000) NOT NULL,
241123
""DisplayName"" TEXT NOT NULL,

Files/MultilingualResources/Files.ar.xlf

+8-12
Original file line numberDiff line numberDiff line change
@@ -1902,10 +1902,6 @@
19021902
<source>Original path</source>
19031903
<target state="translated">المسار الأصلي</target>
19041904
</trans-unit>
1905-
<trans-unit id="SettingsUseFileListCache.Header" translate="yes" xml:space="preserve">
1906-
<source>Cache files and folders for better performance</source>
1907-
<target state="translated">ملفات ومجلدات ذاكرة التخزين المؤقت لأداء أفضل</target>
1908-
</trans-unit>
19091905
<trans-unit id="AppBarButtonAdd.Label" translate="yes" xml:space="preserve">
19101906
<source>Add</source>
19111907
<target state="translated" state-qualifier="tm-suggestion">إضافة</target>
@@ -2326,14 +2322,6 @@
23262322
<source>Disconnect</source>
23272323
<target state="needs-review-translation" state-qualifier="tm-suggestion">قطع الاتصال</target>
23282324
</trans-unit>
2329-
<trans-unit id="PreemptiveCacheParallelLimit.Header" translate="yes" xml:space="preserve">
2330-
<source>Preemptive cache parallel limit (smaller numbers should work better for hard drives)</source>
2331-
<target state="new">Preemptive cache parallel limit (smaller numbers should work better for hard drives)</target>
2332-
</trans-unit>
2333-
<trans-unit id="SettingsUsePreemptiveCache.Header" translate="yes" xml:space="preserve">
2334-
<source>Use preemptive cache (preload entries in child directories on navigation)</source>
2335-
<target state="new">Use preemptive cache (preload entries in child directories on navigation)</target>
2336-
</trans-unit>
23372325
<trans-unit id="BundlesWidgetMoreOptionsButton.AutomationProperties.Name" translate="yes" xml:space="preserve">
23382326
<source>More bundles options</source>
23392327
<target state="new">More bundles options</target>
@@ -2454,6 +2442,14 @@
24542442
<source>Files is running as administrator</source>
24552443
<target state="new">Files is running as administrator</target>
24562444
</trans-unit>
2445+
<trans-unit id="PinItemToStart.Text" translate="yes" xml:space="preserve">
2446+
<source>Pin to the Start Menu</source>
2447+
<target state="new">Pin to the Start Menu</target>
2448+
</trans-unit>
2449+
<trans-unit id="UnpinItemFromStart.Text" translate="yes" xml:space="preserve">
2450+
<source>Unpin from the Start Menu</source>
2451+
<target state="new">Unpin from the Start Menu</target>
2452+
</trans-unit>
24572453
</group>
24582454
</body>
24592455
</file>

0 commit comments

Comments
 (0)