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

adhawkins <adhawkins.aktinb-NUepA2SMhDQqspMVqqL2D+4xXEVPTSb/[email protected]> Sun, 22 May 2022 08:43:32 +0000
Newsgroups gmane.music.equipment.slimdevices.devel
Organization Logitech Squeezebox Forums
Message-ID <[email protected]>
Thanks for the info, will go back and take a look at applying it to the
code.

Regarding the 'non-recursive', I've managed to implement this and it
seems to be fairly efficient. What I do is:

Iterate over all the directories I found the file in.
Run a query on the database to select all the files that match this
directory (which will also include the ones below it)
For each result, get the directory its in.
If this directory is the same as the directory I searched for, add it
in.

Perhaps not the most efficient way of doing it, but it basically mirrors
what the original code does. It seems to work correctly.

The code is below:


Code:
--------------------
    
  	my $sth_recursive_insert;
  	my $sth_select;
  	my $sth_insert;
  
  	if ($recursive) {
  		$sth_recursive_insert = $dbh->prepare('
  			INSERT OR IGNORE INTO library_track (library, track)
  			SELECT ?, tracks.id
  			FROM tracks
  			WHERE url like ?
  			AND content_type NOT IN ("cpl", "src", "ssp", "dir")
  		');
  	} else {
  		$sth_select = $dbh->prepare('
  			SELECT id, url FROM tracks
  				WHERE url like ? AND content_type NOT IN ("cpl", "src", "ssp", "dir")
  				ORDER BY url
  		');
  
  		$sth_insert = $dbh->prepare('
  			INSERT OR IGNORE INTO library_track (library, track) values (?, ?)
  		');
  	}
  
  	foreach my $dir ( @includeDirs ) {
  		my $pathSearch = Slim::Utils::Misc::fileURLFromPath($dir) . File::Spec->catfile('', '') . "%";
  		main::DEBUGLOG && $log->is_debug && $log->debug("$libName: Including '$dir', pathSearch: '$pathSearch'");
  
  		if ($recursive) {
  			main::DEBUGLOG && $log->is_debug && $log->debug("Doing recursive");
  
  			$sth_recursive_insert->execute($id, $pathSearch);
  		} else {
  			$sth_select->execute($pathSearch);
  
  			while ( my ($trackid, $url) = $sth_select->fetchrow_array ) {
  				my $trackDir = dirname(Slim::Utils::Misc::pathFromFileURL($url));
  
  				main::DEBUGLOG && $log->is_debug && $log->debug("dir for '$url' is '$trackDir'");
  
  				if ( $trackDir eq $dir ) {
  					main::DEBUGLOG && $log->is_debug && $log->debug("Inserting");
  
  					$sth_insert->execute($id, $trackid);
  				}
  			}
  		}
  	}
  
--------------------


How does that look?

Andy


------------------------------------------------------------------------
adhawkins's Profile: http://forums.slimdevices.com/member.php?userid=650
View this thread: http://forums.slimdevices.com/showthread.php?t=116400