10000 Feature: Add disk based thumbnail caching system by workbysaran · Pull Request #17991 · files-community/Files · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@workbysaran
Copy link
Contributor
@workbysaran workbysaran commented Dec 24, 2025

Resolved / Related Issues

Related to #4180

Addresses performance issues caused by repeated Shell API thumbnail generation by introducing a disk based LRU cache and a centralized ThumbnailService.

Steps used to test these changes

  1. Navigate to a folder with mixed file types (images, PDFs, etc.) and verify that thumbnails are generated and cached
  2. Scroll down and then back up, and verify that thumbnails load instantly from the cache
  3. Navigate away from the folder and return to it, and verify that thumbnails load instantly from the cache
  4. Restart the app, navigate to the same folder, and verify that thumbnails load instantly from the cache
  5. Modify an image file and verify that the thumbnail is regenerated
  6. Switch between different views and verify that thumbnails are generated correctly for each view

@yaira2 yaira2 self-requested a review December 24, 2025 15:43
@yaira2 yaira2 added the ready for review Pull requests that are ready for review label Dec 24, 2025
Copy link
Member
@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are looking good as far as I can tell as of now. This code will still remain for the time being but we should use the built-in windows API to get thumbnail cache in the future. (Looks like IThumbnailProvider in the new Storage Abstraction API WindowsStorableHelpers.GetThumbnail already calls, nice)

@yaira2 yaira2 marked this pull request as draft January 7, 2026 23:39
@yaira2 yaira2 requested a review from 0x5bfa January 13, 2026 21:49
@yaira2 yaira2 marked this pull request as ready for review January 13, 2026 21:49
Signed-off-by: Yair <39923744+yaira2@users.noreply.github.com>
@yaira2 yaira2 force-pushed the sg/feature-thumbnail-cache branch from ea17047 to e0fb9ae Compare January 14, 2026 00:19
@yaira2 yaira2 force-pushed the sg/feature-thumbnail-cache branch from 1962f3a to 14e6e26 Compare January 15, 2026 16:52
Comment on lines +234 to +244
var fileSizeOnDisk = Win32Helper.GetFileSizeOnDisk(file);
totalSizeOnDisk += fileSizeOnDisk ?? 0;
}

return totalSizeOnDisk;
}
catch
{
return 0;
}
}

This comment was marked as outdated.

Comment on lines +22 to +26
return await thumbnailService.GetThumbnailAsync(
path,
(int)size,
isFolder,
iconOptions);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: FileThumbnailHelper.GetIconAsync lacks a CancellationToken parameter, preventing cancellation of long-running thumbnail generation tasks and potentially causing resource leaks when navigating away from folders.
Severity: MEDIUM

Suggested Fix

Propagate a CancellationToken through the call chain. Modify FileThumbnailHelper.GetIconAsync to accept a CancellationToken and pass it to IThumbnailService.GetThumbnailAsync. Ensure the underlying implementation in ShellApiThumbnailGenerator.GenerateAsync also respects the token to enable cancellation of the task.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs#L22-L26

Potential issue: The `FileThumbnailHelper.GetIconAsync` method does not accept a
`CancellationToken`. Consequently, when called from `ShellViewModel.LoadThumbnailAsync`,
the cancellation token available in the view model cannot be propagated down to the
thumbnail generation service. The cancellation check
`cancellationToken.ThrowIfCancellationRequested()` occurs only *after* the `await` on
`GetIconAsync` completes. This means that if a user navigates away, the underlying Win32
Shell API calls will continue to run to completion, consuming CPU and STA thread
resources unnecessarily, which can lead to performance degradation.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Pull requests that are ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0