+
Skip to content

Conversation

fholzer
Copy link
Contributor

@fholzer fholzer commented May 13, 2025

fixes #159

Might also help with #47 & #105

DMS hides directories that don't contain any "files of interest". The way this is currently implemented is that when a directory is browsed, readContainer is called, which, via cdsObjectToUpnpavObject, objectChildCount calls readContainer on all child directories. Further, when encountering a file, cdsObjectToUpnpavObject calls ffmpegProbe. This means that ffmpegProbe is called on all files in the whole directory subtree on which Browse/BrowseDirectChildren was called. This is also the case when BrowseDirectChildren is called on the root path.

While DMS won't do a full library scan on startup, it will do a full scan on the first BrowseDirectChildren call it receives, likely on the root path.

It seems to me that this was implemented, at least in part, to hide folders that don't contain files of interest. It needs to recursively check child folders to see if there's any files of interest, though in doing so it scans all files in all subdirectories, which technically isn't needed for this use case.

This PR addresses the issue having a different code path for determining what subdirectories to show/hide. Currently, when cdsObjectToUpnpavObject is called on a directory, it calls objectChildCount to determine whether the current folder is of interest. This in turn calls readDir, which calls cdsObjectToUpnpavObject, which calls ffmpegProbe. The proposed change makes objectChildCount no longer call readContainer, but instead iterate over the contained files and directories directly, calling a new func isOfInterest on each to determine whether that object should count towards the child count of the containing folder. isOfInterest calls func objectHasChildren which was updated to no longer call objectChildCount, which would result in the recursion, but instead has the same "is of interest" checks that cdsObjectToUpnpavObject uses. This means it will also walk the directory tree, and will call ffmpegProbe only on files in direct subdirectories for which BrowseDirectChildren was called, instead of all files in the tree.

Old:

graph TD;
    BrowseDirectChildren-->readContainer;
    readContainer-->cdsObjectToUpnpavObject;
    cdsObjectToUpnpavObject-->|isDirectory| objectChildCount;
    objectChildCount-->readContainer;
    cdsObjectToUpnpavObject-->|isFile| ffmpegProbe;
Loading

New:

graph TD;
    BrowseDirectChildren-->readContainer;
    readContainer-->cdsObjectToUpnpavObject;
    cdsObjectToUpnpavObject-->|isFile| ffmpegProbe;
    cdsObjectToUpnpavObject-->|isDirectory| objectChildCount;
    objectChildCount-->isOfInterest;
    isOfInterest-->|isDirectory| objectHasChildren;
    objectHasChildren-->isOfInterest
Loading

@fholzer fholzer force-pushed the fix-recursive-ffprobe branch from 67a47bb to 839707b Compare May 18, 2025 12:29
@fholzer
Copy link
Contributor Author

fholzer commented May 18, 2025

Updated to make the diff a little cleaner, and add more detailed PR description.

@anacrolix
Copy link
Owner

That makes a lot of sense. I'll have a quick check.

@anacrolix anacrolix merged commit 4f28a5e into anacrolix:master May 20, 2025
@anacrolix
Copy link
Owner

Thanks. It's a small change but might help a lot of people.

This app is very old and needs a big overhaul in caching, logging, and how it does the scanning. But I don't use it anymore and there's no financial reason for me to do that.

Great contribution, thanks!

@fholzer fholzer deleted the fix-recursive-ffprobe branch May 20, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow on first access for large libraries

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载