From c3f2bf57dee93c2480b4c2f6a5aed72fff3fc463 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 24 Jan 2013 14:02:50 -0500 Subject: [PATCH] CC-4873: Airtime takes 7 seconds to load 32K (very small) from db -further optimization by looking at the preferred time scale --- .../controllers/ScheduleController.php | 11 +++++--- airtime_mvc/application/models/Show.php | 26 ++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index cd48ccb13..0b384911e 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -129,14 +129,19 @@ class ScheduleController extends Zend_Controller_Action $user = new Application_Model_User($userInfo->id); $editable = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); - $calendar_interval = Application_Model_Preference::GetCalendarTimeInterval(); + $calendar_interval = Application_Model_Preference::GetCalendarTimeScale(); + Logging::info($calendar_interval); if ($calendar_interval == "agendaDay") { + list($start, $end) = Application_Model_Show::getStartEndCurrentDayView(); } else if ($calendar_interval == "agendaWeek") { + list($start, $end) = Application_Model_Show::getStartEndCurrentWeekView(); } else if ($calendar_interval == "month") { + list($start, $end) = Application_Model_Show::getStartEndCurrentMonthView(); + } else { + Logging::error("Invalid Calendar Interval '$calendar_interval'"); } - list($start, $end) = Application_Model_Show::getStartEndCurrentMonthView(); - $events = &Application_Model_Show::getFullCalendarEvents($start, $end, $editable); + $events = &Application_Model_Show::getFullCalendarEvents($start, $end, $editable); $this->view->events = $events; } diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 2d66d5443..933c2c841 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -2183,11 +2183,35 @@ SQL; while (date('w', $first_day_of_calendar_month_view) != $weekStart) { $first_day_of_calendar_month_view -= 60*60*24; } - $last_day_of_calendar_view = $first_day_of_calendar_month_view + 3600*24*41; + $last_day_of_calendar_view = $first_day_of_calendar_month_view + 3600*24*42; $start = new DateTime("@".$first_day_of_calendar_month_view); $end = new DateTime("@".$last_day_of_calendar_view); return array($start, $end); } + + public static function getStartEndCurrentWeekView() { + $first_day_of_calendar_week_view = mktime(0, 0, 0, date("n"), date("j")); + $weekStart = Application_Model_Preference::GetWeekStartDay(); + while (date('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; + + $start = new DateTime("@".$first_day_of_calendar_week_view); + $end = new DateTime("@".$last_day_of_calendar_view); + + return array($start, $end); + } + + public static function getStartEndCurrentDayView() { + $today = mktime(0, 0, 0, date("n"), date("j")); + $tomorrow = $today + 3600*24; + + $start = new DateTime("@".$today); + $end = new DateTime("@".$tomorrow); + + return array($start, $end); + } }