Major performance improvements to the Dashboard and Calendar views

* Close the PHP session for writing as early as possible in most AJAX
  calls for those views
* Reduce the number of roundtrips to the server in both the Dashboard
  and Calendar views by putting the data in our HTML response (this
  makes a massive difference)
* Eliminated a couple of unneccessary AJAX calls
* Use lazy loading in full calendar
* Fixed a bug in the week view that only occurs near the end of the
  week (date->gmdate bug!)
This commit is contained in:
Albert Santoni 2015-03-13 18:22:27 -04:00
parent b49e98693b
commit 34de6da2c7
10 changed files with 48 additions and 16 deletions

View File

@ -403,6 +403,7 @@ class LibraryController extends Zend_Controller_Action
public function contentsFeedAction() public function contentsFeedAction()
{ {
session_write_close();
$params = $this->getRequest()->getParams(); $params = $this->getRequest()->getParams();
# terrible name for the method below. it does not only search files. # terrible name for the method below. it does not only search files.

View File

@ -50,6 +50,13 @@ class ScheduleController extends Zend_Controller_Action
$baseUrl = Application_Common_OsPath::getBaseDir(); $baseUrl = Application_Common_OsPath::getBaseDir();
$foo = new ScheduleController($this->getRequest(), $this->getResponse());
$foo->eventFeedPreloadAction();
//$foo->eventFeedAction();
$events = json_encode($foo->view->events);
//$timescale =
//$this->getRequest()->getParam("view", "week");
$this->view->headScript()->appendScript( $this->view->headScript()->appendScript(
"var calendarPref = {};\n". "var calendarPref = {};\n".
"calendarPref.weekStart = ".Application_Model_Preference::GetWeekStartDay().";\n". "calendarPref.weekStart = ".Application_Model_Preference::GetWeekStartDay().";\n".
@ -58,7 +65,7 @@ class ScheduleController extends Zend_Controller_Action
"calendarPref.timeScale = '".Application_Model_Preference::GetCalendarTimeScale()."';\n". "calendarPref.timeScale = '".Application_Model_Preference::GetCalendarTimeScale()."';\n".
"calendarPref.timeInterval = ".Application_Model_Preference::GetCalendarTimeInterval().";\n". "calendarPref.timeInterval = ".Application_Model_Preference::GetCalendarTimeInterval().";\n".
"calendarPref.weekStartDay = ".Application_Model_Preference::GetWeekStartDay().";\n". "calendarPref.weekStartDay = ".Application_Model_Preference::GetWeekStartDay().";\n".
"var calendarEvents = null;" "var calendarEvents = $events;"
); );
$this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
@ -116,6 +123,7 @@ class ScheduleController extends Zend_Controller_Action
public function eventFeedAction() public function eventFeedAction()
{ {
session_write_close();
$service_user = new Application_Service_UserService(); $service_user = new Application_Service_UserService();
$currentUser = $service_user->getCurrentUser(); $currentUser = $service_user->getCurrentUser();
@ -137,6 +145,7 @@ class ScheduleController extends Zend_Controller_Action
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new Application_Model_User($userInfo->id); $user = new Application_Model_User($userInfo->id);
$editable = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $editable = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
session_write_close();
$calendar_interval = Application_Model_Preference::GetCalendarTimeScale(); $calendar_interval = Application_Model_Preference::GetCalendarTimeScale();
if ($calendar_interval == "agendaDay") { if ($calendar_interval == "agendaDay") {
@ -155,6 +164,7 @@ class ScheduleController extends Zend_Controller_Action
public function getCurrentShowAction() public function getCurrentShowAction()
{ {
session_write_close();
$currentShow = Application_Model_Show::getCurrentShow(); $currentShow = Application_Model_Show::getCurrentShow();
if (!empty($currentShow)) { if (!empty($currentShow)) {
$this->view->si_id = $currentShow[0]["instance_id"]; $this->view->si_id = $currentShow[0]["instance_id"];
@ -296,6 +306,7 @@ class ScheduleController extends Zend_Controller_Action
public function getCurrentPlaylistAction() public function getCurrentPlaylistAction()
{ {
session_write_close();
$range = Application_Model_Schedule::GetPlayOrderRangeOld(); $range = Application_Model_Schedule::GetPlayOrderRangeOld();
$show = Application_Model_Show::getCurrentShow(); $show = Application_Model_Show::getCurrentShow();
@ -704,6 +715,7 @@ class ScheduleController extends Zend_Controller_Action
*/ */
public function setTimeScaleAction() public function setTimeScaleAction()
{ {
session_write_close();
Application_Model_Preference::SetCalendarTimeScale($this->_getParam('timeScale')); Application_Model_Preference::SetCalendarTimeScale($this->_getParam('timeScale'));
} }

View File

@ -246,6 +246,7 @@ class ShowbuilderController extends Zend_Controller_Action
public function checkBuilderFeedAction() public function checkBuilderFeedAction()
{ {
session_write_close();
$request = $this->getRequest(); $request = $this->getRequest();
$show_filter = intval($request->getParam("showFilter", 0)); $show_filter = intval($request->getParam("showFilter", 0));
$my_shows = intval($request->getParam("myShows", 0)); $my_shows = intval($request->getParam("myShows", 0));
@ -265,6 +266,7 @@ class ShowbuilderController extends Zend_Controller_Action
public function builderFeedAction() public function builderFeedAction()
{ {
session_write_close();
$current_time = time(); $current_time = time();
$request = $this->getRequest(); $request = $this->getRequest();

View File

@ -37,6 +37,7 @@ class UsersettingsController extends Zend_Controller_Action
public function setLibraryDatatableAction() public function setLibraryDatatableAction()
{ {
session_write_close();
$request = $this->getRequest(); $request = $this->getRequest();
$settings = $request->getParam("settings"); $settings = $request->getParam("settings");
@ -45,6 +46,7 @@ class UsersettingsController extends Zend_Controller_Action
public function getLibraryDatatableAction() public function getLibraryDatatableAction()
{ {
session_write_close();
$data = Application_Model_Preference::getCurrentLibraryTableSetting(); $data = Application_Model_Preference::getCurrentLibraryTableSetting();
if (!is_null($data)) { if (!is_null($data)) {
$this->view->settings = $data; $this->view->settings = $data;
@ -53,6 +55,7 @@ class UsersettingsController extends Zend_Controller_Action
public function setTimelineDatatableAction() public function setTimelineDatatableAction()
{ {
session_write_close();
$request = $this->getRequest(); $request = $this->getRequest();
$settings = $request->getParam("settings"); $settings = $request->getParam("settings");
@ -61,17 +64,11 @@ class UsersettingsController extends Zend_Controller_Action
public function getTimelineDatatableAction() public function getTimelineDatatableAction()
{ {
$start = microtime(true); session_write_close();
$data = Application_Model_Preference::getTimelineDatatableSetting(); $data = Application_Model_Preference::getTimelineDatatableSetting();
if (!is_null($data)) { if (!is_null($data)) {
$this->view->settings = $data; $this->view->settings = $data;
} }
$end = microtime(true);
Logging::debug("getting timeline datatables info took:");
Logging::debug(floatval($end) - floatval($start));
} }
public function remindmeAction() public function remindmeAction()

View File

@ -19,6 +19,23 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
})(window,document,'script','dataLayer','GTM-55N6NH');</script> })(window,document,'script','dataLayer','GTM-55N6NH');</script>
<!-- End Google Tag Manager --> <!-- End Google Tag Manager -->
<script type="text/javascript">
//Awful hack to speed up loading - Embed the schedule in the response so that the dashboard
//doesn't have to make a separate AJAX request to get this data.
var schedulePreLoaded = <?php
require_once("ScheduleController.php");
$front = Zend_Controller_Front::getInstance();
$foo = new ScheduleController($front->getRequest(), $front->getResponse());
$foo->getCurrentPlaylistAction();
echo(json_encode($foo->view));
?>;
parseItems(schedulePreLoaded.entries);
parseSourceStatus(schedulePreLoaded.source_status);
parseSwitchStatus(schedulePreLoaded.switch_status);
</script>
<?php echo $this->partial('partialviews/trialBox.phtml', array("is_trial"=>$this->isTrial(), "trial_remain"=> $this->trialRemaining())) ?> <?php echo $this->partial('partialviews/trialBox.phtml', array("is_trial"=>$this->isTrial(), "trial_remain"=> $this->trialRemaining())) ?>
<div id="Panel"> <div id="Panel">
<div class="logo"></div> <div class="logo"></div>

View File

@ -1446,9 +1446,9 @@ SQL;
} }
public static function getStartEndCurrentWeekView() { public static function getStartEndCurrentWeekView() {
$first_day_of_calendar_week_view = mktime(0, 0, 0, date("n"), date("j")); $first_day_of_calendar_week_view = mktime(0, 0, 0, gmdate("n"), gmdate("j"));
$weekStart = Application_Model_Preference::GetWeekStartDay(); $weekStart = Application_Model_Preference::GetWeekStartDay();
while (date('w', $first_day_of_calendar_week_view) != $weekStart) { while (gmdate('w', $first_day_of_calendar_week_view) != $weekStart) {
$first_day_of_calendar_week_view -= 60*60*24; $first_day_of_calendar_week_view -= 60*60*24;
} }
$last_day_of_calendar_view = $first_day_of_calendar_week_view + 3600*24*7; $last_day_of_calendar_view = $first_day_of_calendar_week_view + 3600*24*7;
@ -1460,7 +1460,7 @@ SQL;
} }
public static function getStartEndCurrentDayView() { public static function getStartEndCurrentDayView() {
$today = mktime(0, 0, 0, date("n"), date("j")); $today = mktime(0, 0, 0, gmdate("n"), gmdate("j"));
$tomorrow = $today + 3600*24; $tomorrow = $today + 3600*24;
$start = new DateTime("@".$today); $start = new DateTime("@".$today);

View File

@ -395,7 +395,6 @@ function getScheduleFromServer(){
parseSourceStatus(data.source_status); parseSourceStatus(data.source_status);
parseSwitchStatus(data.switch_status); parseSwitchStatus(data.switch_status);
showName = data.show_name; showName = data.show_name;
setTimeout(getScheduleFromServer, serverUpdateInterval);
}, error:function(jqXHR, textStatus, errorThrown){}}); }, error:function(jqXHR, textStatus, errorThrown){}});
} }
@ -456,8 +455,9 @@ var stream_window = null;
function init() { function init() {
//begin producer "thread" //begin producer "thread"
getScheduleFromServer(); //getScheduleFromServer();
setInterval(getScheduleFromServer, serverUpdateInterval);
//begin consumer "thread" //begin consumer "thread"
secondsTimer(); secondsTimer();

View File

@ -890,7 +890,7 @@ var AIRTIME = (function(AIRTIME) {
} }
}); });
checkImportStatus(); //checkImportStatus();
checkLibrarySCUploadStatus(); checkLibrarySCUploadStatus();
addQtipToSCIcons(); addQtipToSCIcons();

View File

@ -362,11 +362,14 @@ function windowResize() {
function preloadEventFeed () { function preloadEventFeed () {
var url = baseUrl+'Schedule/event-feed-preload'; var url = baseUrl+'Schedule/event-feed-preload';
var d = new Date(); var d = new Date();
createFullCalendar({calendarInit: calendarPref});
/*
$.post(url, {format: "json", cachep: d.getTime()}, function(json){ $.post(url, {format: "json", cachep: d.getTime()}, function(json){
calendarEvents = json.events; calendarEvents = json.events;
createFullCalendar({calendarInit: calendarPref}); createFullCalendar({calendarInit: calendarPref});
}); });
*/
} }
var initialLoad = true; var initialLoad = true;

View File

@ -312,7 +312,7 @@ function createFullCalendar(data){
], ],
contentHeight: mainHeight, contentHeight: mainHeight,
theme: true, theme: true,
lazyFetching: false, lazyFetching: true,
serverTimestamp: parseInt(data.calendarInit.timestamp, 10), serverTimestamp: parseInt(data.calendarInit.timestamp, 10),
serverTimezoneOffset: parseInt(data.calendarInit.timezoneOffset, 10), serverTimezoneOffset: parseInt(data.calendarInit.timezoneOffset, 10),