Skip to content

Commit

Permalink
Invalidate cached XML browser sub-feeds on quantity mismatch
Browse files Browse the repository at this point in the history
If a client does a query for a small amount of data followed by a query
for a larger amount of data, the second query returned partially invalid
results since it returned the data of the first query, padded with
empty items. Fix this by re-querying data in that case.

Fixes #1298

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 committed Jan 16, 2025
1 parent cb5b8e4 commit ca548ee
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Slim/Control/XMLBrowser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ sub _cliQuery_done {
delete $subFeed->{fetched};
}

# Invalidate previously fetched data if it was fetched with a smaller quantity than requested now
if ($subFeed->{fetched} && $subFeed->{fetchSize} && $subFeed->{fetchSize} < $quantity) {
main::DEBUGLOG && $log->is_debug && $log->debug(" Invalidating short cached data (has ", $subFeed->{fetchSize}, " want $quantity)");
delete $subFeed->{fetched};
}

# If the feed is another URL, fetch it and insert it into the
# current cached feed
if ( (!$subFeed->{'type'} || ($subFeed->{'type'} ne 'audio')) && defined $subFeed->{'url'} && !$subFeed->{'fetched'}
Expand Down Expand Up @@ -1499,14 +1505,15 @@ sub _cliQuery_done {
# After fetching, insert the contents into the original feed
sub _cliQuerySubFeed_done {
my ( $feed, $params ) = @_;
my $request = $params->{request};

# If there's a command we need to run, run it. This is used in various
# places to trigger actions from an OPML result, such as to start playing
# a new Pandora radio station
if ( $feed->{command} ) {

my @p = map { uri_unescape($_) } split / /, $feed->{command};
my $client = $params->{request}->client();
my $client = $request->client();

if ($client) {
main::DEBUGLOG && $log->is_debug && $log->debug( "Executing command: " . Data::Dump::dump(\@p) );
Expand Down Expand Up @@ -1545,6 +1552,7 @@ sub _cliQuerySubFeed_done {
}

$subFeed->{'fetched'} = 1;
$subFeed->{'fetchSize'} = $request->getParam('_quantity');

# Pass-through forceRefresh flag
if ( $feed->{forceRefresh} ) {
Expand Down

0 comments on commit ca548ee

Please sign in to comment.