CC-3331 : Optimize "Now Playing" to load in less than 1/2 second

- The logic to build the NowPlaying list was updated to refactor the quering of the database for playlist tracks played from in the loop per show ID to outside the loop for a given duration. The resulting list was then partitioned off for each show.
This commit is contained in:
Daniel 2012-02-17 11:13:34 -05:00
parent a4a41f301f
commit 6d71ec8c9c
3 changed files with 123 additions and 4 deletions

View File

@ -54,13 +54,13 @@ class Application_Model_Nowplaying
return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", "");
}
public static function GetDataGridData($viewType, $dateString){
public static function GetDataGridData($viewType, $dateString){
if ($viewType == "now"){
$dateTime = new DateTime("now", new DateTimeZone("UTC"));
$timeNow = $dateTime->format("Y-m-d H:i:s");
$startCutoff = 60;
$startCutoff = 60;
$endCutoff = 86400; //60*60*24 - seconds in a day
} else {
$date = new Application_Model_DateHelper;
@ -75,14 +75,84 @@ class Application_Model_Nowplaying
$data = array();
$showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff);
//get all the pieces to be played between the start cut off and the end cut off.
$scheduledItems = Application_Model_ShowInstance::getScheduleItemsForAllShowsInRange($timeNow, $startCutoff, $endCutoff);
$orderedScheduledItems;
foreach ($scheduledItems as $scheduledItem){
$orderedScheduledItems[$scheduledItem['instance_id']][] = $scheduledItem;
}
foreach ($showIds as $showId){
$instanceId = $showId['id'];
//gets the show information
$si = new Application_Model_ShowInstance($instanceId);
$showId = $si->getShowId();
$showId = $si->getShowId();
$show = new Application_Model_Show($showId);
$showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceStart());
$showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceEnd());
//append show header row
$data[] = self::CreateHeaderRow($show->getName(), $showStartDateTime->format("Y-m-d H:i:s"), $showEndDateTime->format("Y-m-d H:i:s"));
$dataTablesRows = self::CreateDatatableRows($orderedScheduledItems[$instanceId]);
//append show audio item rows
$data = array_merge($data, $dataTablesRows);
//append show gap time row
$gapTime = self::FormatDuration($si->getShowEndGapTime(), true);
if ($si->isRecorded())
$data[] = self::CreateRecordingRow($si);
else if ($gapTime > 0)
$data[] = self::CreateGapRow($gapTime);
}
$rows = Application_Model_Show::GetCurrentShow($timeNow);
Application_Model_Show::ConvertToLocalTimeZone($rows, array("starts", "ends", "start_timestamp", "end_timestamp"));
return array("currentShow"=>$rows, "rows"=>$data);
}
public static function GetDataGridDataOLD($viewType, $dateString){
if ($viewType == "now"){
$dateTime = new DateTime("now", new DateTimeZone("UTC"));
$timeNow = $dateTime->format("Y-m-d H:i:s");
$startCutoff = 60;
//$endCutoff = 2592000; // 30 days
//$endCutoff = 604800; // 7 days
$endCutoff = 259200; // 3 days
//$endCutoff = 86400; //60*60*24 - seconds in a day
} else {
$date = new Application_Model_DateHelper;
$time = $date->getTime();
$date->setDate($dateString." ".$time);
$timeNow = $date->getUtcTimestamp();
$startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff();
}
$data = array();
$showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff);
//Logging::log(print_r($showIds, true));
foreach ($showIds as $showId){
$instanceId = $showId['id'];
//gets the show information
$si = new Application_Model_ShowInstance($instanceId);
//Logging::log(print_r($si, true));
$showId = $si->getShowId();
$show = new Application_Model_Show($showId);
//Logging::log(print_r($show, true));
$showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceStart());
$showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceEnd());
@ -90,7 +160,9 @@ class Application_Model_Nowplaying
$data[] = self::CreateHeaderRow($show->getName(), $showStartDateTime->format("Y-m-d H:i:s"), $showEndDateTime->format("Y-m-d H:i:s"));
$scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff);
//Logging::log(print_r($scheduledItems, true));
$dataTablesRows = self::CreateDatatableRows($scheduledItems);
//Logging::log(print_r($dataTablesRows, true));
//append show audio item rows
$data = array_merge($data, $dataTablesRows);

View File

@ -757,6 +757,42 @@ class Application_Model_ShowInstance {
return $CC_DBC->GetAll($sql);
}
public static function getScheduleItemsForAllShowsInRange($timeNow, $start, $end)
{
global $CC_DBC, $CC_CONFIG;
$sql = "SELECT"
." si.starts as show_starts,"
." si.ends as show_ends,"
." si.rebroadcast as rebroadcast,"
." st.starts as item_starts,"
." st.ends as item_ends,"
." st.clip_length as clip_length,"
." ft.track_title as track_title,"
." ft.artist_name as artist_name,"
." ft.album_title as album_title,"
." s.name as show_name,"
." si.id as instance_id,"
." pt.name as playlist_name"
." FROM $CC_CONFIG[showInstances] si"
." LEFT JOIN $CC_CONFIG[scheduleTable] st"
." ON st.instance_id = si.id"
." LEFT JOIN $CC_CONFIG[playListTable] pt"
." ON st.playlist_id = pt.id"
." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id"
." LEFT JOIN $CC_CONFIG[showTable] s"
." ON si.show_id = s.id"
." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')"
." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))"
." AND (st.starts < si.ends)"
." ORDER BY si.id, si.starts, st.starts";
return $CC_DBC->GetAll($sql);
}
public function getLastAudioItemEnd(){
global $CC_DBC;

View File

@ -12,3 +12,14 @@ RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteBase /
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/json