Re: SimpleLibraryViews plugin update increases library build time by a factor of 10

mherger <mherger.aktc5z-NUepA2SMhDQqspMVqqL2D+4xXEVPTSb/[email protected]> Sun, 22 May 2022 06:22:59 +0000
Newsgroups gmane.music.equipment.slimdevices.devel
Organization Logitech Squeezebox Forums
Message-ID <[email protected]>
adhawkins wrote: 
> One question, to go through all the libraries I'm iterating over the
> result of 'Slim::Utils::Misc::getAudioDirs()'. Is that the right thing
> to do?

I'm not sure I understand. Yes, you'll have to can all of
getAudioDirs(). But no, you don't have to do this for all libraries. You
could do it once, and collect a list of all library name files you find.
Keep this around in a (module) global variable:


Code:
--------------------
    {
  library1 => [ dir1, dir2, .. ],
  library2 => [ dir2, dirx, .. ],
  ...
  }
--------------------


So for the next library you'd only have to evaluate the folders in
respective hash entry instead of crawling the filesystem once again.

adhawkins wrote: 
> Any suggestions on how to do this filtering? Perl is far from my first
> language!

Sort the $dirs before processing them. Keep track of the previous value.
If your current folder is a sub-folder of the previous, skip its
processing


Code:
--------------------
    
  	my $previousDir;
  	foreach my $dir ( @includeDirs ) {
  		next if $previousDir && $dir =~ /^\Q$previousDir\E/;
  		$previousDir = $dir;
  
  		my $pathSearch = Slim::Utils::Misc::fileURLFromPath($dir) . '/%';
  		$log->debug("$libName: Including '$dir', pathSearch: '$pathSearch'");
  		$sth_insert->execute($id, $pathSearch);
  	}
  
  
--------------------


You might notice I've modified the $pathSearch, too: using catfile() for
the URL is wrong. That function would concatenate paths and file names
following the operating system's conventions (eg. "/" vs. "" on
Windows). But the URL used for the $pathSearch would always have a
forward slash (to be confirmed - haven't tested this code!).

adhawkins wrote: 
> Also, I've had a request to make the recursive behaviour configurable.
> Given the way the scanning code works, is there any way I could achieve
> this? The SQL SELECT statement that finds the tracks would need to only
> accept ones that are in a directory that has a matching file.

Yeah, that's trickier. Hmm... You'd probably have to use a different SQL
query using REGEXP instead of LIKE for non-recursive. Then create a
regex which would match the path, but no more slash after that.


Code:
--------------------
    
  if ($nonRecursive) {
  $pathSearch = '^\Q' . Slim::Utils::Misc::fileURLFromPath($dir) . '/\E[^\/]*';
  }
  
--------------------


Again: I haven't tested this. I'm not sure it would work. Please give it
a try. I'd have to check what regexes SQL supports.



Michael

"It doesn't work - what shall I do?" - "Please check your server.log
and/or scanner.log file!"
(LMS: Settings/Information)
------------------------------------------------------------------------
mherger's Profile: http://forums.slimdevices.com/member.php?userid=50
View this thread: http://forums.slimdevices.com/showthread.php?t=116400