From 34de6da2c7b0f659947668e25d9df4df7f48cd16 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 13 Mar 2015 18:22:27 -0400 Subject: [PATCH] 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!) --- .../controllers/LibraryController.php | 1 + .../controllers/ScheduleController.php | 14 +++++++++++++- .../controllers/ShowbuilderController.php | 2 ++ .../controllers/UsersettingsController.php | 11 ++++------- .../application/layouts/scripts/layout.phtml | 17 +++++++++++++++++ airtime_mvc/application/models/Show.php | 6 +++--- .../public/js/airtime/dashboard/dashboard.js | 6 +++--- .../public/js/airtime/library/library.js | 2 +- .../airtime/schedule/full-calendar-functions.js | 3 +++ .../public/js/airtime/schedule/schedule.js | 2 +- 10 files changed, 48 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 8c635baa6..5bafc1438 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -403,6 +403,7 @@ class LibraryController extends Zend_Controller_Action public function contentsFeedAction() { + session_write_close(); $params = $this->getRequest()->getParams(); # terrible name for the method below. it does not only search files. diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 452788b23..5f81335de 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -50,6 +50,13 @@ class ScheduleController extends Zend_Controller_Action $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( "var calendarPref = {};\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.timeInterval = ".Application_Model_Preference::GetCalendarTimeInterval().";\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'); @@ -116,6 +123,7 @@ class ScheduleController extends Zend_Controller_Action public function eventFeedAction() { + session_write_close(); $service_user = new Application_Service_UserService(); $currentUser = $service_user->getCurrentUser(); @@ -137,6 +145,7 @@ class ScheduleController extends Zend_Controller_Action $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $editable = $user->isUserType(array(UTYPE_SUPERADMIN, UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); + session_write_close(); $calendar_interval = Application_Model_Preference::GetCalendarTimeScale(); if ($calendar_interval == "agendaDay") { @@ -155,6 +164,7 @@ class ScheduleController extends Zend_Controller_Action public function getCurrentShowAction() { + session_write_close(); $currentShow = Application_Model_Show::getCurrentShow(); if (!empty($currentShow)) { $this->view->si_id = $currentShow[0]["instance_id"]; @@ -296,6 +306,7 @@ class ScheduleController extends Zend_Controller_Action public function getCurrentPlaylistAction() { + session_write_close(); $range = Application_Model_Schedule::GetPlayOrderRangeOld(); $show = Application_Model_Show::getCurrentShow(); @@ -704,6 +715,7 @@ class ScheduleController extends Zend_Controller_Action */ public function setTimeScaleAction() { + session_write_close(); Application_Model_Preference::SetCalendarTimeScale($this->_getParam('timeScale')); } diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index 5638cf719..65c2bb355 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -246,6 +246,7 @@ class ShowbuilderController extends Zend_Controller_Action public function checkBuilderFeedAction() { + session_write_close(); $request = $this->getRequest(); $show_filter = intval($request->getParam("showFilter", 0)); $my_shows = intval($request->getParam("myShows", 0)); @@ -265,6 +266,7 @@ class ShowbuilderController extends Zend_Controller_Action public function builderFeedAction() { + session_write_close(); $current_time = time(); $request = $this->getRequest(); diff --git a/airtime_mvc/application/controllers/UsersettingsController.php b/airtime_mvc/application/controllers/UsersettingsController.php index 9d8154578..bda20e122 100644 --- a/airtime_mvc/application/controllers/UsersettingsController.php +++ b/airtime_mvc/application/controllers/UsersettingsController.php @@ -37,6 +37,7 @@ class UsersettingsController extends Zend_Controller_Action public function setLibraryDatatableAction() { + session_write_close(); $request = $this->getRequest(); $settings = $request->getParam("settings"); @@ -45,6 +46,7 @@ class UsersettingsController extends Zend_Controller_Action public function getLibraryDatatableAction() { + session_write_close(); $data = Application_Model_Preference::getCurrentLibraryTableSetting(); if (!is_null($data)) { $this->view->settings = $data; @@ -53,6 +55,7 @@ class UsersettingsController extends Zend_Controller_Action public function setTimelineDatatableAction() { + session_write_close(); $request = $this->getRequest(); $settings = $request->getParam("settings"); @@ -61,17 +64,11 @@ class UsersettingsController extends Zend_Controller_Action public function getTimelineDatatableAction() { - $start = microtime(true); - + session_write_close(); $data = Application_Model_Preference::getTimelineDatatableSetting(); if (!is_null($data)) { $this->view->settings = $data; } - - $end = microtime(true); - - Logging::debug("getting timeline datatables info took:"); - Logging::debug(floatval($end) - floatval($start)); } public function remindmeAction() diff --git a/airtime_mvc/application/layouts/scripts/layout.phtml b/airtime_mvc/application/layouts/scripts/layout.phtml index df5d0281b..709d32b26 100644 --- a/airtime_mvc/application/layouts/scripts/layout.phtml +++ b/airtime_mvc/application/layouts/scripts/layout.phtml @@ -19,6 +19,23 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= })(window,document,'script','dataLayer','GTM-55N6NH'); + + partial('partialviews/trialBox.phtml', array("is_trial"=>$this->isTrial(), "trial_remain"=> $this->trialRemaining())) ?>
diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 73925fc65..b744fb0cc 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1446,9 +1446,9 @@ SQL; } 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(); - 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; } $last_day_of_calendar_view = $first_day_of_calendar_week_view + 3600*24*7; @@ -1460,7 +1460,7 @@ SQL; } 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; $start = new DateTime("@".$today); diff --git a/airtime_mvc/public/js/airtime/dashboard/dashboard.js b/airtime_mvc/public/js/airtime/dashboard/dashboard.js index e4ffc1faf..f18c2cf57 100644 --- a/airtime_mvc/public/js/airtime/dashboard/dashboard.js +++ b/airtime_mvc/public/js/airtime/dashboard/dashboard.js @@ -395,7 +395,6 @@ function getScheduleFromServer(){ parseSourceStatus(data.source_status); parseSwitchStatus(data.switch_status); showName = data.show_name; - setTimeout(getScheduleFromServer, serverUpdateInterval); }, error:function(jqXHR, textStatus, errorThrown){}}); } @@ -456,8 +455,9 @@ var stream_window = null; function init() { //begin producer "thread" - getScheduleFromServer(); - + //getScheduleFromServer(); + setInterval(getScheduleFromServer, serverUpdateInterval); + //begin consumer "thread" secondsTimer(); diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 7f5471bfa..24499e57c 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -890,7 +890,7 @@ var AIRTIME = (function(AIRTIME) { } }); - checkImportStatus(); + //checkImportStatus(); checkLibrarySCUploadStatus(); addQtipToSCIcons(); diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js index 01b1096d5..f51c6c738 100644 --- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js +++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js @@ -362,11 +362,14 @@ function windowResize() { function preloadEventFeed () { var url = baseUrl+'Schedule/event-feed-preload'; var d = new Date(); + createFullCalendar({calendarInit: calendarPref}); +/* $.post(url, {format: "json", cachep: d.getTime()}, function(json){ calendarEvents = json.events; createFullCalendar({calendarInit: calendarPref}); }); + */ } var initialLoad = true; diff --git a/airtime_mvc/public/js/airtime/schedule/schedule.js b/airtime_mvc/public/js/airtime/schedule/schedule.js index d734853ea..bf2937bcd 100644 --- a/airtime_mvc/public/js/airtime/schedule/schedule.js +++ b/airtime_mvc/public/js/airtime/schedule/schedule.js @@ -312,7 +312,7 @@ function createFullCalendar(data){ ], contentHeight: mainHeight, theme: true, - lazyFetching: false, + lazyFetching: true, serverTimestamp: parseInt(data.calendarInit.timestamp, 10), serverTimezoneOffset: parseInt(data.calendarInit.timezoneOffset, 10),