Feat: Add performance optimizations for iCloud directory scanning #191
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.
Description
First of all, thank you for this great library! 🙏 I'm integrating it in our app and also want to add directory tree reports, but I've hit a wall with iCloud performance. The issue is that when scanning folders on iCloud,
FileManagermethods likedisplayName,attributesOfItem, andcontentsOfDirectorycan each take multiple seconds when files aren't fully synced. So a single directory can take over a minute to scan, making the feature unusable.Changes
I added two things:
NameExtractionenum that lets you skip the slowdisplayNamecall. You can use.rawto get the name directly from the path (it's instant but not localized), or stick with.localizedfor the current behaviorskipDirectoryContentsclosure that lets you bail out of traversing specific folders. It usesfileExistsinstead ofattributesOfItemto check directory type, which is much faster on iCloud. The directory still shows up in the tree, it just doesn't scan insideBoth default to the current behavior so nothing breaks.
This solves our iCloud issue, but the feature is general-purpose. It works for skipping any folders you don't want to traverse (at any level). Sorry for not discussing first. Would appreciate any feedback on whether this fits the library's direction.