From 9fd3b43bb212d34f226b307df6ed381aca5b5ca9 Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 23 Jan 2013 16:12:16 -0500 Subject: [PATCH] CC-4873: Airtime takes 7 seconds to load 32K (very small) from db Made improvement by accessing db just once to determine if each show instance is full or not --- airtime_mvc/application/models/Show.php | 12 +++----- .../application/models/ShowInstance.php | 28 +++++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 9db5e5f0b..a675fc637 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1753,7 +1753,9 @@ SQL; $nowEpoch = time(); $content_count = Application_Model_ShowInstance::getContentCount( $p_start, $p_end); + $isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end); $timezone = date_default_timezone_get(); + $utc = new DateTimeZone("UTC"); foreach ($shows as $show) { $options = array(); @@ -1763,8 +1765,6 @@ SQL; $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]); } - $utc = new DateTimeZone("UTC"); - if (isset($show["parent_starts"])) { $parentStartsDT = new DateTime($show["parent_starts"], $utc); $parentStartsEpoch = intval($parentStartsDT->format("U")); @@ -1795,14 +1795,10 @@ SQL; } } - - $showInstance = new Application_Model_ShowInstance( - $show["instance_id"]); - $options["show_empty"] = (array_key_exists($show['instance_id'], $content_count)) ? 0 : 1; - - $options["show_partial_filled"] = $showInstance->showPartialFilled(); + + $options["show_partial_filled"] = $isFull[$show['instance_id']]; $events[] = &self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr); diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 14def6321..f1d9d8173 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -661,10 +661,8 @@ SQL; return $returnStr; } - - public static function getContentCount($p_start, $p_end) - { + { $sql = << '00:00:00' -AND time_filled < ends - starts -AND file_id IS null AS partial_filled -FROM cc_show_instances -WHERE id = :instance_id +SELECT id, ends-starts < time_filled as filled +from cc_show_instances +WHERE ends > :p_start::TIMESTAMP +AND starts < :p_end::TIMESTAMP SQL; - $res = Application_Common_Database::prepareAndExecute($sql, - array(':instance_id' => $this->_instanceId), 'all'); + $res = Application_Common_Database::prepareAndExecute($sql, array( + ':p_start' => $p_start->format("Y-m-d G:i:s"), + ':p_end' => $p_end->format("Y-m-d G:i:s")) + , 'all'); - return $res[0]["partial_filled"]; + $isFilled = array(); + foreach ($res as $r) { + $isFilled[$r['id']] = $r['filled']; + } + + return $isFilled; } public function showEmpty()