-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Feature: Add disk based thumbnail caching system #17991
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
Open
workbysaran
wants to merge
40
commits into
files-community:main
Choose a base branch
from
workbysaran:sg/feature-thumbnail-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+844
−73
Open
Changes from 22 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
4b089c4
Feature: Add disk based thumbnail caching system
workbysaran 3d2bab2
Fix: Exclude thumbnail cache directory from being cached
workbysaran 69cc86f
Feature: Added Clear Cache button to clear thumbnail cache
workbysaran a876d95
Fix: Resolved deadlock in thumbnail cache eviction
workbysaran f10cf97
Feature: Added expandable section for thumbnail cache settings and a …
workbysaran 626a129
Fix: Removed icons from the sub-settings of the thumbnail settings
workbysaran 7d22445
Feature: Display thumbnail cache size on disk and disable Clear Cache…
workbysaran 83f39a6
Code Quality: Localization of thumbnail cache settings
workbysaran 2f39834
Merge branch 'main' into sg/feature-thumbnail-cache
yair100 e0fb9ae
Moved cache settings to Experimental
yair100 1b36c80
Code Quality: Added comments for the IThumbnail contracts
workbysaran 224c558
Code Quality: Moved FileThumbnailHelper initialization to AppLifecycl…
workbysaran 14e6e26
Updated Strings
yair100 28a5074
Code Quality: Simplified FileThumbnailHelper to use static DI pattern
workbysaran db1f496
Fix: Use MiB instead of MB for thumbnail cache size terminology
workbysaran be95e17
Fix: Invalidate thumbnail cache when cloud file sync state changes
workbysaran f5043b5
Fix: Add in-memory icon cache and cache-first thumbnail lookup
workbysaran 3693dec
Fix: Use SHChangeNotifyRegister to detect OneDrive file updates
workbysaran d747203
Revert "Fix: Use SHChangeNotifyRegister to detect OneDrive file updates"
workbysaran d7f7698
Fix: Avoid extension-based icon cache for per-file types(eg: .exe, .l…
workbysaran c1af7a1
Fix: Probe Shell cache before writing thumbnails to disk to avoid cac…
workbysaran acc050c
Fix: Avoid thumbnail flicker when thumbnail cache is disabled
workbysaran b2902ad
Merge branch 'main' into sg/feature-thumbnail-cache
workbysaran 3ab385b
Fix: Prevent concurrent writes to the same thumbnail cache file
workbysaran 1acc69a
Fix: Use ReturnIconOnly for folders when thumbnail cache is disabled
workbysaran 589e89e
Perf: Replace file-based thumbnail cache with SQLite for faster lookups
workbysaran d9c9ea1
Refactor: Use per-operation SQLite connections and fix PRAGMA synchro…
workbysaran a1e01a4
Fix: Fixed folder thumbnails showing generic icons when thumbnail cac…
workbysaran 40c3003
Fix: Skip thumbnail disk cache for cloud drive folders
workbysaran 0291ad0
Fix: Propagate CancellationToken to prevent stale thumbnails from bei…
workbysaran d7fabcc
Fix: Resolve OneDrive folder thumbnail race condition by tracking pla…
workbysaran 71dd378
Fix: Revert cloud thumbnail load delay from 15s to 0.5s
workbysaran 44e7bdf
Refactor: Simplify thumbnail cache by removing placeholder tracking
workbysaran 5dad312
Increase delay to 1 second
yair100 5a16d66
Debug: Add thumbnail load timing diagnostics
workbysaran 7d37bc8
Merge branch 'sg/feature-thumbnail-cache' of https://github.com/workb…
workbysaran 00a6f07
Perf: Decouple icon overlay from thumbnail display path
workbysaran be94e38
Perf: Decoupled overlay from thumbnail path and remove dead deferred …
workbysaran 589dcd3
Refactor: Thumbnail loading and add async fallback
workbysaran 1544b9b
Fix: Thumbnail loading concurrency management when calling with Retur…
workbysaran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) Files Community | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Files.App.Data.Contracts | ||
| { | ||
| /// <summary> | ||
| /// Stores and retrieves cached thumbnails. | ||
| /// </summary> | ||
| public interface IThumbnailCache | ||
| { | ||
| /// <summary> | ||
| /// Retrieves a cached thumbnail. | ||
| /// </summary> | ||
| /// <returns>Thumbnail bytes, or null if not cached.</returns> | ||
| Task<byte[]?> GetAsync(string path, int size, IconOptions options, CancellationToken ct); | ||
|
|
||
| /// <summary> | ||
| /// Stores a thumbnail in the cache. | ||
| /// </summary> | ||
| Task SetAsync(string path, int size, IconOptions options, byte[] thumbnail, CancellationToken ct); | ||
|
|
||
| /// <summary> | ||
| /// Gets the current cache size in bytes. | ||
| /// </summary> | ||
| Task<long> GetSizeAsync(); | ||
|
|
||
| /// <summary> | ||
| /// Reduces cache size to the specified target in bytes. | ||
| /// </summary> | ||
| Task EvictToSizeAsync(long targetSizeBytes); | ||
|
|
||
| /// <summary> | ||
| /// Removes all cached thumbnails. | ||
| /// </summary> | ||
| Task ClearAsync(); | ||
|
|
||
| /// <summary> | ||
| /// Retrieves a cached icon from the in-memory icon cache. | ||
| /// </summary> | ||
| /// <returns>Icon bytes, or null if not cached.</returns> | ||
| byte[]? GetIcon(string extension, int size); | ||
|
|
||
| /// <summary> | ||
| /// Stores an icon in the in-memory icon cache. | ||
| /// </summary> | ||
| void SetIcon(string extension, int size, byte[] iconData); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) Files Community | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Files.App.Data.Contracts | ||
| { | ||
| /// <summary> | ||
| /// Generates thumbnails for specific file types. | ||
| /// </summary> | ||
| public interface IThumbnailGenerator | ||
| { | ||
| /// <summary> | ||
| /// Gets the file extensions this generator supports. | ||
| /// </summary> | ||
| IEnumerable<string> SupportedTypes { get; } | ||
|
|
||
| /// <summary> | ||
| /// Generates a thumbnail for the specified path. | ||
| /// </summary> | ||
| /// <returns>Thumbnail bytes, or null if generation fails.</returns> | ||
| Task<byte[]?> GenerateAsync( | ||
| string path, | ||
| int size, | ||
| bool isFolder, | ||
| IconOptions options, | ||
| CancellationToken ct); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (c) Files Community | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Files.App.Data.Contracts | ||
| { | ||
| /// <summary> | ||
| /// Provides thumbnail retrieval and cache management. | ||
| /// </summary> | ||
| public interface IThumbnailService | ||
| { | ||
| /// <summary> | ||
| /// Gets a thumbnail for the specified path. | ||
| /// </summary> | ||
| /// <returns>Thumbnail bytes, or null if unavailable.</returns> | ||
| Task<byte[]?> GetThumbnailAsync( | ||
| string path, | ||
| int size, | ||
| bool isFolder, | ||
| IconOptions options = IconOptions.None, | ||
| CancellationToken ct = default); | ||
|
|
||
| /// <summary> | ||
| /// Gets a cached thumbnail without calling the Shell API. | ||
| /// Returns null if not found in the cache. | ||
| /// </summary> | ||
| Task<byte[]?> GetCachedThumbnailAsync( | ||
| string path, | ||
| int size, | ||
| bool isFolder, | ||
| IconOptions options, | ||
| CancellationToken ct = default); | ||
|
|
||
| /// <summary> | ||
| /// Registers a thumbnail generator. | ||
| /// </summary> | ||
| void RegisterGenerator(IThumbnailGenerator generator); | ||
|
|
||
| /// <summary> | ||
| /// Clears all cached thumbnails. | ||
| /// </summary> | ||
| Task ClearCacheAsync(); | ||
|
|
||
| /// <summary> | ||
| /// Gets the current cache size in bytes. | ||
| /// </summary> | ||
| Task<long> GetCacheSizeAsync(); | ||
|
|
||
| /// <summary> | ||
| /// Reduces cache size to the specified target in bytes. | ||
| /// </summary> | ||
| Task EvictCacheAsync(long targetSizeBytes); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Files.App/Services/Thumbnails/Generators/ShellApiThumbnailGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Files Community | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Files.App.Services.Thumbnails.Generators | ||
| { | ||
| public sealed class ShellApiThumbnailGenerator : IThumbnailGenerator | ||
| { | ||
| private readonly ILogger _logger; | ||
|
|
||
| public IEnumerable<string> SupportedTypes => ["*"]; | ||
|
|
||
| public ShellApiThumbnailGenerator(ILogger<ShellApiThumbnailGenerator> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public async Task<byte[]?> GenerateAsync( | ||
| string path, | ||
| int size, | ||
| bool isFolder, | ||
| IconOptions options, | ||
| CancellationToken ct) | ||
| { | ||
| return await STATask.Run(() => | ||
| Win32Helper.GetIcon(path, size, isFolder, options), | ||
| _logger); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.