core icon indicating copy to clipboard operation
core copied to clipboard

Local media folder fetch indefinitely

Open BenoitAnastay opened this issue 2 years ago • 3 comments

The problem

When I mount an hard drive with mixed files in the media folder, the UI cannot longer display any file, the loading animal turn indefinitely

What version of Home Assistant Core has the issue?

core-2022.9.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Local media

Link to integration documentation on our website

https://www.home-assistant.io/integrations/media_source/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

There is no errors in logs, but the thread is still running when I stop HA.

My guess is that the folder crawler isn't optimized or there is something that makes it loop indefinitely.

I'll do more inspection of this bug latter

BenoitAnastay avatar Sep 20 '22 20:09 BenoitAnastay

Hey there @hunterjm, mind taking a look at this issue as it has been labeled with an integration (media_source) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

After looking at the source code, I guess that the culprit is that recursivity https://github.com/home-assistant/core/blob/3f512e38db9ed3e85626190077134f9274282e2a/homeassistant/components/media_source/local_source.py#L119-L122

            base.children = [
                self._browse_media(source_dir_id, "")
                for source_dir_id in self.hass.config.media_dirs
            ]

If the folder have many files and subdirectories it's will never finish the processing

When we navigate into folders we only need to love the current level and not all subfolder recursively

I do not have enough confidence with HA to rewrite this integration

BenoitAnastay avatar Sep 20 '22 20:09 BenoitAnastay

Is it possible to reopen this issue ?

BenoitAnastay avatar Oct 28 '22 19:10 BenoitAnastay