insidegui / WWDC

The unofficial WWDC app for macOS
https://wwdc.io
BSD 2-Clause "Simplified" License
8.63k stars 783 forks source link

If user sets directory with a lot of files as Download folder, app will freeze #584

Closed subdan closed 4 years ago

subdan commented 5 years ago

`enumerator.allObjects` freezes the app because I have a lot of files in the Documents directory.

<img width="2160" alt="Screenshot 2019-09-29 at 20 48 02" src="https://user-images.githubusercontent.com/410293/65836685-71c5ca80-e2fa-11e9-9e34-55f1d54e7b1f.png">

As a solution, we can disallow choosing an non-empty directory as Download folder.

Also there is no button to reset Download folder to default value. I think we should add this button. I can open Pull request with this button.
allenhumphreys commented 5 years ago

Thanks for investigating this @subdan , unfortunately we've known about this issue for a while but just haven't had time to investigate a really good direction on a fix.

One potential short-term solution is to limit the recursion on the file discovery to a set depth. This would likely fix the issue for 95% of use cases as directories with massive numbers of files are usually nested quite deep.

This would be as simple as:

var files = [String]()
for case let path as String in enumerator {
    // Limit recursion to 2 levels
    if enumerator.level > 2 {
        enumerator.skipDescendants()
    }
    files.append(path)
}

A more robust solution would be to only look for files that might actually exist. Since the download filename/path for all possible videos is theoretically known, we could build that list (in the background), then check the existence of expected files.