Index: /Users/mh/Documents/workspace/SC7.0/Slim/Control/Queries.pm =================================================================== --- /Users/mh/Documents/workspace/SC7.0/Slim/Control/Queries.pm (revision 16955) +++ /Users/mh/Documents/workspace/SC7.0/Slim/Control/Queries.pm (working copy) @@ -530,7 +530,7 @@ } my $count = $rs->count; - my $totalCount = $count; + my $totalCount = $count || 0; # Various artist handling. Don't do if pref is off, or if we're # searching, or if we have a track @@ -543,25 +543,10 @@ $count_va = Slim::Schema->rs('Album')->search($where_va, $attr_va)->count; # fix the index and counts if we have to include VA - if ($count_va) { - - $totalCount++; - - # return one less result as we've added the VA item in the first chunk - if (!$index) { - $quantity--; - } - - # decrease the index in subsequent queries - elsif ($index + $quantity >= $count) { - $index--; - $count_va = 0; - } + $totalCount = _fixCount($count_va, \$index, \$quantity, $count); - else { - $count_va = 0; - } - } + # don't ad the VA item on subsequent queries + $count_va = ($count_va && !$index); } # now build the result @@ -1440,7 +1425,9 @@ $request->addResult("rescan", 1); } - $count += 0; +$log->error($insertAll, ', ', $index, ', ', $quantity, ', ', $count); + my $totalCount = _fixCount($insertAll, \$index, \$quantity, $count); +$log->error($insertAll, ', ', $index, ', ', $quantity, ', ', $count); my ($valid, $start, $end) = $request->normalize(scalar($index), scalar($quantity), $count); @@ -1451,8 +1438,11 @@ $request->addResult('offset', $start) if $menuMode; if ($insertAll) { - ($chunkCount, $count) = _playAll(start => $start, end => $end, listCount => $count, chunkCount => $chunkCount, request => $request, loopname => $loopname); + + ($chunkCount, $totalCount) = _playAll(start => $start, end => $end, listCount => $totalCount, chunkCount => $chunkCount, request => $request, loopname => $loopname); + } + for my $eachitem (@data[$start..$end]) { next if ($eachitem == undef); @@ -1591,7 +1581,7 @@ } } - $request->addResult('count', $count); + $request->addResult('count', $totalCount); # we might have changed - flush to the db to be in sync. $topLevelObj->update; @@ -4826,6 +4816,9 @@ } } + else { + $listCount++; + } return($chunkCount, $listCount); @@ -4851,6 +4844,34 @@ $cache = {}; } + +# fix the count in case we're adding additional items +# (play all, VA etc.) to the resultset +sub _fixCount { + my $insertItem = shift; + my $index = shift; + my $quantity = shift; + my $count = shift; + + my $totalCount = $count || 0; + + if ($insertItem) { + + # return one less result as we only add the additional item in the first chunk + if ( !$$index ) { + $$quantity--; + } + + # decrease the index in subsequent queries + elsif ( $$index + $$quantity >= $count ) { + $$index--; + } + } + + return $totalCount; +} + + =head1 SEE ALSO L @@ -4858,5 +4879,4 @@ =cut 1; - __END__