CC-3331: Optimize "Now Playing" to load in less than 1/2 second
- Reorganized the now playing to find all the scheduled items within two time frames instead of in a loop per show id. - I've cut the time in half
This commit is contained in:
parent
6d71ec8c9c
commit
5cb99e9532
3 changed files with 92 additions and 157 deletions
|
@ -12,7 +12,7 @@ class Application_Model_Nowplaying
|
|||
|
||||
$epochNow = time();
|
||||
|
||||
foreach ($p_dbRows as $dbRow){
|
||||
foreach ($p_dbRows as $dbRow) {
|
||||
|
||||
$showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['show_starts']);
|
||||
$showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['show_ends']);
|
||||
|
@ -77,7 +77,8 @@ class Application_Model_Nowplaying
|
|||
$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);
|
||||
$scheduledItems = Application_Model_Schedule::getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff);
|
||||
|
||||
$orderedScheduledItems;
|
||||
foreach ($scheduledItems as $scheduledItem){
|
||||
$orderedScheduledItems[$scheduledItem['instance_id']][] = $scheduledItem;
|
||||
|
@ -116,70 +117,6 @@ class Application_Model_Nowplaying
|
|||
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());
|
||||
|
||||
//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"));
|
||||
|
||||
$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);
|
||||
|
||||
//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 ShouldShowPopUp(){
|
||||
$today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y"));
|
||||
$remindDate = Application_Model_Preference::GetRemindMeDate();
|
||||
|
|
|
@ -294,6 +294,41 @@ class Application_Model_Schedule {
|
|||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
public static function getScheduleItemsInRange($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 static function GetShowInstanceItems($instance_id)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
@ -577,4 +612,3 @@ class Application_Model_Schedule {
|
|||
$p_view->addNewShow = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -757,42 +757,6 @@ 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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue