Skip to content

Icon cache and Task.Run tweaks #9885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static async Task<List<ListedItem>> ListEntries(
{
var sampler = new IntervalSampler(500);
var tempList = new List<ListedItem>();
var hasNextFile = false;
var count = 0;

IUserSettingsService userSettingsService = Ioc.Default.GetService<IUserSettingsService>();
Expand Down Expand Up @@ -123,14 +122,13 @@ public static async Task<List<ListedItem>> ListEntries(
break;
}

hasNextFile = FindNextFile(hFile, out findData);
if (intermediateAction != null && (count == 32 || sampler.CheckNow()))
{
await intermediateAction(tempList);
// clear the temporary list every time we do an intermediate action
tempList.Clear();
}
} while (hasNextFile);
} while (FindNextFile(hFile, out findData));

FindClose(hFile);
return tempList;
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/Helpers/FileListCache/FileListCacheController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ private FileListCacheController()

private readonly ConcurrentDictionary<string, string> fileNamesCache = new ConcurrentDictionary<string, string>();

public Task<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken)
public ValueTask<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken)
{
if (fileNamesCache.TryGetValue(path, out var displayName))
{
return Task.FromResult(displayName);
return ValueTask.FromResult(displayName);
}

return Task.FromResult<string>(null);
return ValueTask.FromResult<string>(null);
}

public Task SaveFileDisplayNameToCache(string path, string displayName)
public ValueTask SaveFileDisplayNameToCache(string path, string displayName)
{
if (displayName == null)
{
fileNamesCache.TryRemove(path, out _);
}

fileNamesCache[path] = displayName;
return Task.CompletedTask;
return ValueTask.CompletedTask;
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/Helpers/FileListCache/IFileListCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Files.App.Helpers.FileListCache
{
internal interface IFileListCache
{
public Task<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken);
public ValueTask<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken);

public Task SaveFileDisplayNameToCache(string path, string displayName);
public ValueTask SaveFileDisplayNameToCache(string path, string displayName);
}
}
Loading