Fix slow browse due to directory walk and ffprobe #160
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.
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, viacdsObjectToUpnpavObject
,objectChildCount
callsreadContainer
on all child directories. Further, when encountering a file,cdsObjectToUpnpavObject
callsffmpegProbe
. This means thatffmpegProbe
is called on all files in the whole directory subtree on whichBrowse/BrowseDirectChildren
was called. This is also the case whenBrowseDirectChildren
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 callsreadDir
, which callscdsObjectToUpnpavObject
, which callsffmpegProbe
. The proposed change makesobjectChildCount
no longer callreadContainer
, but instead iterate over the contained files and directories directly, calling a newfunc isOfInterest
on each to determine whether that object should count towards the child count of the containing folder.isOfInterest
callsfunc objectHasChildren
which was updated to no longer callobjectChildCount
, which would result in the recursion, but instead has the same "is of interest" checks thatcdsObjectToUpnpavObject
uses. This means it will also walk the directory tree, and will callffmpegProbe
only on files in direct subdirectories for whichBrowseDirectChildren
was called, instead of all files in the tree.Old:
New: