Whenever the Television plugin needs to load its XML file of TV listings,
the whole server hangs waiting for the parsing to complete. This
interrupts the music and any attempted remote commands.
I realized that the major slowdown is the XML parsing itself, and that can
be done in a preprocessing phase outside of the Slim server, such as right
after downloading the XML file. The preprocessor can create a file in
perl syntax, which can be parsed much more quickly by the slim server.
First I have a separate program to do the conversion. I call it xml2perl.
It can either take standard input and write to standard output, or take a
filename on the command line and write to a .pl file in the same
directory. For example, both "listings.xml" and just plain "listings" are
converted to "listings.pl".
Next I have a patch to Television.pm. This patch checks the filename
configured as $data_location, and if it's a .xml file it parses the XML
just as before. But if it's not a .xml file, it loads it assuming it's a
perl file created by xml2perl.
#!/usr/bin/perl
# xml2perl - preprocess an XML file into a perl structure
use XML::Simple;
use Data:umper;
my $data_location = shift;
$data_location = '-' unless $data_location;
my $xmlsimple = XML::Simple->new( forcearray => 1, keyattr => [] );
my $response = $xmlsimple->XMLin($data_location);
my $perl = Dumper($response);
if ($data_location eq '-') {
print $perl;
} else {
my $newfile = $data_location;
$newfile =~ s/\.xml$//; # file may not end in .xml
$newfile =~ s/$/.pl/;
open F, '>', $newfile;
print F $perl;
close F;
}
__END__
--- Television.pm.orig 2004-02-06 21:28:45.000000000 -0500
+++ Television.pm 2004-03-28 22:19:03.000000000 -0500
@@ -446,9 +446,16 @@
}
$curr_item{$client}='';
$client->update();
-
- my $xmlsimple = XML::Simple->new( forcearray => 1, keyattr => [] );
- my $response = $xmlsimple->XMLin($data_location);
+
+ my $response;
+ if ($data_location =~ /\.xml$/i) {
+ my $xmlsimple = XML::Simple->new( forcearray => 1, keyattr => [] );
+ $response = $xmlsimple->XMLin($data_location);
+ } else {
+ local our $VAR1; # assume file defines this variable
+ do $data_location;
+ $response = $VAR1;
+ }
$curr_item{$client}='.';
$client->update();
--
==============================| "A slice of life isn't the whole cake
Rob Funk <rfunk (AT) funknet (DOT) net> | One tooth will never make a full grin"
http://www.funknet.net/rfunk | -- Chris Mars, "Stuck in Rewind"
Results 1 to 1 of 1
Thread: Television plugin optimization
Hybrid View
-
2004-03-28, 20:48 #1Rob FunkGuest
Television plugin optimization

umper;
Reply With Quote
