CC-4873: Airtime takes 7 seconds to load 32K (very small) from db

- put makeFullCalendarEvent inline with loop
- removed unnecessary epoch time conversion
This commit is contained in:
denise 2013-01-23 17:33:34 -05:00
parent adaab6ba96
commit 78f617cacb
1 changed files with 37 additions and 19 deletions

View File

@ -1750,12 +1750,13 @@ SQL;
$interval = $p_start->diff($p_end); $interval = $p_start->diff($p_end);
$days = $interval->format('%a'); $days = $interval->format('%a');
$shows = Application_Model_Show::getShows($p_start, $p_end); $shows = Application_Model_Show::getShows($p_start, $p_end);
$nowEpoch = time();
$content_count = Application_Model_ShowInstance::getContentCount( $content_count = Application_Model_ShowInstance::getContentCount(
$p_start, $p_end); $p_start, $p_end);
$isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end); $isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end);
$timezone = date_default_timezone_get(); $timezone = date_default_timezone_get();
$current_timezone = new DateTimeZone($timezone);
$utc = new DateTimeZone("UTC"); $utc = new DateTimeZone("UTC");
$now = new DateTime("now", $utc);
foreach ($shows as $show) { foreach ($shows as $show) {
$options = array(); $options = array();
@ -1767,7 +1768,6 @@ SQL;
if (isset($show["parent_starts"])) { if (isset($show["parent_starts"])) {
$parentStartsDT = new DateTime($show["parent_starts"], $utc); $parentStartsDT = new DateTime($show["parent_starts"], $utc);
$parentStartsEpoch = intval($parentStartsDT->format("U"));
} }
$startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $startsDT = DateTime::createFromFormat("Y-m-d G:i:s",
@ -1775,35 +1775,53 @@ SQL;
$endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $endsDT = DateTime::createFromFormat("Y-m-d G:i:s",
$show["ends"], $utc); $show["ends"], $utc);
$startsEpochStr = $startsDT->format("U");
$endsEpochStr = $endsDT->format("U");
$startsEpoch = intval($startsEpochStr);
$endsEpoch = intval($endsEpochStr);
$startsDT->setTimezone(new DateTimeZone($timezone));
$endsDT->setTimezone(new DateTimeZone($timezone));
if( $p_editable ) { if( $p_editable ) {
if ($show["record"] && $nowEpoch > $startsEpoch) { if ($show["record"] && $now > $startsDT) {
$options["editable"] = false; $options["editable"] = false;
} elseif ($show["rebroadcast"] && } elseif ($show["rebroadcast"] &&
$nowEpoch > $parentStartsEpoch) { $now > $parentStartsDT) {
$options["editable"] = false; $options["editable"] = false;
} elseif ($nowEpoch < $endsEpoch) { } elseif ($now < $endsDT) {
$options["editable"] = true; $options["editable"] = true;
} }
} }
$startsDT->setTimezone($current_timezone);
$endsDT->setTimezone($current_timezone);
$options["show_empty"] = (array_key_exists($show['instance_id'], $options["show_empty"] = (array_key_exists($show['instance_id'],
$content_count)) ? 0 : 1; $content_count)) ? 0 : 1;
$options["show_partial_filled"] = !$isFull[$show['instance_id']]; $options["show_partial_filled"] = !$isFull[$show['instance_id']];
$events[] = &self::makeFullCalendarEvent($show, $options, $event = array();
$startsDT, $endsDT, $startsEpochStr, $endsEpochStr);
}
$event["id"] = intval($show["instance_id"]);
$event["title"] = $show["name"];
$event["start"] = $startsDT->format("Y-m-d H:i:s");
$event["end"] = $endsDT->format("Y-m-d H:i:s");
$event["allDay"] = false;
$event["showId"] = intval($show["show_id"]);
$event["record"] = intval($show["record"]);
$event["rebroadcast"] = intval($show["rebroadcast"]);
$event["soundcloud_id"] = is_null($show["soundcloud_id"])
? -1 : $show["soundcloud_id"];
//event colouring
if ($show["color"] != "") {
$event["textColor"] = "#".$show["color"];
}
if ($show["background_color"] != "") {
$event["color"] = "#".$show["background_color"];
}
foreach ($options as $key => $value) {
$event[$key] = $value;
}
$events[] = $event;
}
return $events; return $events;
} }
@ -1820,7 +1838,7 @@ SQL;
return $percent; return $percent;
} }
private static function &makeFullCalendarEvent(&$show, $options=array(), $startDateTime, $endDateTime, $startsEpoch, $endsEpoch) /* private static function &makeFullCalendarEvent(&$show, $options=array(), $startDateTime, $endDateTime, $startsEpoch, $endsEpoch)
{ {
$event = array(); $event = array();
@ -1851,7 +1869,7 @@ SQL;
} }
return $event; return $event;
} }*/
/* Takes in a UTC DateTime object. /* Takes in a UTC DateTime object.
* Converts this to local time, since cc_show days * Converts this to local time, since cc_show days