[Slim-Checkins] r10956 - in /trunk/server/Slim: Music/Info.pm
Web/Pages/Playlist.pm
adrian at svn.slimdevices.com
adrian at svn.slimdevices.com
Wed Dec 13 13:47:04 PST 2006
Author: adrian
Date: Wed Dec 13 13:47:04 2006
New Revision: 10956
URL: http://svn.slimdevices.com?rev=10956&view=rev
Log:
Bug: N/A
Description: reduce cpu hit of playlist refresh by caching html rather
than params, avoiding redundant template processing
Modified:
trunk/server/Slim/Music/Info.pm
trunk/server/Slim/Web/Pages/Playlist.pm
Modified: trunk/server/Slim/Music/Info.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Music/Info.pm?rev=10956&r1=10955&r2=10956&view=diff
==============================================================================
--- trunk/server/Slim/Music/Info.pm (original)
+++ trunk/server/Slim/Music/Info.pm Wed Dec 13 13:47:04 2006
@@ -490,13 +490,26 @@
$format = 'TITLE';
- } elsif (defined($client)) {
+ } else {
+
+ $format = standardTitleFormat($client);
+
+ }
+
+ return displayText($client, $track, $format);
+}
+
+# format string for standard title, potentially client specific
+sub standardTitleFormat {
+ my $client = shift;
+
+ if (defined($client)) {
# in array syntax this would be
# $titleFormat[$clientTitleFormat[$clientTitleFormatCurr]] get
# the title format
- $format = Slim::Utils::Prefs::getInd("titleFormat",
+ return Slim::Utils::Prefs::getInd("titleFormat",
# at the array index of the client titleformat array
$client->prefGet("titleFormat",
# which is currently selected
@@ -507,10 +520,8 @@
} else {
# in array syntax this would be $titleFormat[$titleFormatWeb]
- $format = Slim::Utils::Prefs::getInd("titleFormat", Slim::Utils::Prefs::get("titleFormatWeb"));
- }
-
- return displayText($client, $track, $format);
+ return Slim::Utils::Prefs::getInd("titleFormat", Slim::Utils::Prefs::get("titleFormatWeb"));
+ }
}
# get display text for object by format, caches all formats for this url for this client
Modified: trunk/server/Slim/Web/Pages/Playlist.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Web/Pages/Playlist.pm?rev=10956&r1=10955&r2=10956&view=diff
==============================================================================
--- trunk/server/Slim/Web/Pages/Playlist.pm (original)
+++ trunk/server/Slim/Web/Pages/Playlist.pm Wed Dec 13 13:47:04 2006
@@ -19,6 +19,8 @@
use Slim::Web::Pages;
my $log = logger('player.playlist');
+
+use constant CACHE_TIME => 300;
sub init {
@@ -82,20 +84,18 @@
$client->currentPlaylistRender() &&
ref($client->currentPlaylistRender()) eq 'ARRAY' &&
$client->currentPlaylistChangeTime() &&
+ $client->currentPlaylistChangeTime() < $client->currentPlaylistRender()->[0] &&
$client->currentPlaylistRender()->[1] eq $params->{'skinOverride'} &&
- $client->currentPlaylistRender()->[2] eq $params->{'start'} &&
- $client->currentPlaylistChangeTime() < $client->currentPlaylistRender()->[0]) {
-
- if (Slim::Utils::Prefs::get("playlistdir")) {
- $params->{'cansave'} = 1;
- }
-
- $log->info("Skipping playlist build - not modified.");
-
- $params->{'playlist_items'} = $client->currentPlaylistRender()->[3];
- $params->{'pageinfo'} = $client->currentPlaylistRender()->[4];
-
- return Slim::Web::HTTP::filltemplatefile("playlist.html", $params);
+ $client->currentPlaylistRender()->[2] eq $params->{'start'} ) {
+
+ $log->info("Returning cached playlist html - not modified.");
+
+ # reset cache timer to forget cached html
+ Slim::Utils::Timers::killTimers($client, \&flushCachedHTML);
+ Slim::Utils::Timers::setTimer($client, time() + CACHE_TIME, \&flushCachedHTML);
+
+ # return cached html as playlist has not changed
+ return $client->currentPlaylistRender()->[3];
}
if (!$songcount) {
@@ -124,16 +124,17 @@
my $currsongind = Slim::Player::Source::playingSongIndex($client);
- my $itemCount = 0;
- my $itemsPerPass = Slim::Utils::Prefs::get('itemsPerPass');
my $itemsPerPage = Slim::Utils::Prefs::get('itemsPerPage');
my $composerIn = Slim::Utils::Prefs::get('composerInArtists');
+ my $titleFormat = Slim::Music::Info::standardTitleFormat($client);
+
$params->{'playlist_items'} = [];
$params->{'myClientState'} = $client;
# This is a hot loop.
# But it's better done all at once than through the scheduler.
+
for my $itemnum ($start..$end) {
# These should all be objects - but be safe.
@@ -145,8 +146,6 @@
$track = Slim::Schema->rs('Track')->objectForUrl($objOrUrl) || do {
logError("Couldn't retrieve objectForUrl: [$objOrUrl] - skipping!");
-
- $itemCount++;
next;
};
}
@@ -171,43 +170,51 @@
} else {
$form{'currentsong'} = undef;
- $form{'title'} = Slim::Music::Info::standardTitle(undef, $track);
+ $form{'title'} = Slim::Music::TitleFormatter::infoFormat($track, $titleFormat);
}
$form{'nextsongind'} = $currsongind + (($itemnum > $currsongind) ? 1 : 0);
push @{$params->{'playlist_items'}}, \%form;
- $itemCount++;
-
- # don't neglect the streams too long, every itemsPerPass idle them
- if (!($itemCount % $itemsPerPass)) {
-
- main::idleStreams();
- }
- }
-
- $log->info("End playlist build. $itemCount items");
-
- # Give some player time after the loop, but before rendering.
- main::idleStreams();
+ # don't neglect the streams too long
+ main::idleStreams();
+ }
+
+ $log->info("End playlist build.");
+
+ my $page = Slim::Web::HTTP::filltemplatefile("playlist.html", $params);
if ($client) {
- # Stick the rendered data into the client object as a stopgap
+ # Cache the rendered html for this page of the playlist in the client object as a temporary
# solution to the cpu spike issue.
+ my $time = time();
+
$client->currentPlaylistRender([
- time(),
+ $time,
($params->{'skinOverride'} || ''),
($params->{'start'}),
- $params->{'playlist_items'},
- $params->{'pageinfo'},
+ $page,
]);
- }
-
- return Slim::Web::HTTP::filltemplatefile("playlist.html", $params),
+
+ $log->info("Caching playlist html.");
+
+ # timer to forget cached html
+ Slim::Utils::Timers::killTimers($client, \&flushCachedHTML);
+ Slim::Utils::Timers::setTimer($client, $time + CACHE_TIME, \&flushCachedHTML);
+ }
+
+ return $page;
}
+sub flushCachedHTML {
+ my $client = shift;
+
+ $log->info("Flushing playlist html cache for client.");
+ $client->currentPlaylistRender(undef);
+}
+
1;
__END__
More information about the checkins
mailing list