CC-4120: memory optimizations for calendar page.

-can now fetch over a year of data at a time
This commit is contained in:
Martin Konecny 2012-07-22 19:14:29 -04:00
parent eba4b688c4
commit aaa0c01e01
2 changed files with 26 additions and 30 deletions

View File

@ -114,7 +114,8 @@ class ScheduleController extends Zend_Controller_Action
$editable = false;
}
$this->view->events = Application_Model_Show::getFullCalendarEvents($start, $end, $editable);
$events = &Application_Model_Show::getFullCalendarEvents($start, $end, $editable);
$this->view->events = $events;
}
public function moveShowAction()

View File

@ -1490,10 +1490,11 @@ class Application_Model_Show {
$sql = "SELECT si1.starts AS starts, si1.ends AS ends, si1.record AS record, si1.rebroadcast AS rebroadcast, si2.starts AS parent_starts,
si1.instance_id AS record_id, si1.show_id AS show_id, show.name AS name,
show.color AS color, show.background_color AS background_color, si1.file_id AS file_id, si1.id AS instance_id,
si1.created AS created, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled
si1.created AS created, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled, f.soundcloud_id
FROM cc_show_instances AS si1
LEFT JOIN cc_show_instances AS si2 ON si1.instance_id = si2.id
LEFT JOIN cc_show AS show ON show.id = si1.show_id
LEFT JOIN cc_files AS f ON f.id = si1.file_id
WHERE si1.modified_instance = FALSE";
//only want shows that are starting at the time or later.
$start_string = $start_timestamp->format("Y-m-d H:i:s");
@ -1510,7 +1511,6 @@ class Application_Model_Show {
OR (si1.starts <= '{$start_string}' AND si1.ends >= '{$end_string}'))";
}
if (isset($excludeInstance)) {
foreach($excludeInstance as $instance) {
$sql_exclude[] = "si1.id != {$instance}";
@ -1521,7 +1521,7 @@ class Application_Model_Show {
$sql = $sql." AND ({$exclude})";
}
$result = $con->query($sql)->fetchAll();
$result = $con->query($sql);
return $result;
}
@ -1578,7 +1578,7 @@ class Application_Model_Show {
* -in UTC time
* @param boolean $editable
*/
public static function getFullCalendarEvents($p_start, $p_end, $p_editable=false)
public static function &getFullCalendarEvents($p_start, $p_end, $p_editable=false)
{
$events = array();
$interval = $p_start->diff($p_end);
@ -1586,11 +1586,12 @@ class Application_Model_Show {
$shows = Application_Model_Show::getShows($p_start, $p_end);
$nowEpoch = time();
$timezone = date_default_timezone_get();
foreach ($shows as $show) {
$options = array();
//only bother calculating percent for week or day view.
if (intval($days) <= 7) {
$options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]);
}
@ -1599,11 +1600,17 @@ class Application_Model_Show {
$parentStartsDT = new DateTime($show["parent_starts"], new DateTimeZone("UTC"));
$parentStartsEpoch = intval($parentStartsDT->format("U"));
}
$startsDT = new DateTime($show["starts"], new DateTimeZone("UTC"));
$endsDT = new DateTime($show["ends"], new DateTimeZone("UTC"));
$startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], new DateTimeZone("UTC"));
$startsEpoch = intval($startsDT->format("U"));
$endsEpoch = intval($endsDT->format("U"));
$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 && $show["record"] && $nowEpoch > $startsEpoch) {
$options["editable"] = false;
@ -1614,7 +1621,7 @@ class Application_Model_Show {
else if ($p_editable && $nowEpoch < $endsEpoch) {
$options["editable"] = true;
}
$events[] = Application_Model_Show::makeFullCalendarEvent($show, $options);
$events[] = &self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr);
}
return $events;
@ -1632,47 +1639,35 @@ class Application_Model_Show {
return $percent;
}
private static function makeFullCalendarEvent($show, $options=array())
private static function &makeFullCalendarEvent(&$show, $options=array(), $startDateTime, $endDateTime, $startsEpoch, $endsEpoch)
{
$event = array();
$startDateTime = new DateTime($show["starts"], new DateTimeZone("UTC"));
$startDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$endDateTime = new DateTime($show["ends"], new DateTimeZone("UTC"));
$endDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
$event["id"] = intval($show["instance_id"]);
$event["title"] = $show["name"];
$event["start"] = $startDateTime->format("Y-m-d H:i:s");
$event["startUnix"] = $startDateTime->format("U");
$event["startUnix"] = $startsEpoch;
$event["end"] = $endDateTime->format("Y-m-d H:i:s");
$event["endUnix"] = $endDateTime->format("U");
$event["endUnix"] = $endsEpoch;
$event["allDay"] = false;
$event["showId"] = intval($show["show_id"]);
$event["record"] = intval($show["record"]);
$event["rebroadcast"] = intval($show["rebroadcast"]);
// get soundcloud_id
if (!is_null($show["file_id"])){
$file = Application_Model_StoredFile::Recall($show["file_id"]);
$soundcloud_id = $file->getSoundCloudId();
}
$event["soundcloud_id"] = isset($soundcloud_id) ? $soundcloud_id : -1;
$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;
}
return $event;
}