Optimized linked shows schedule filling

* Fairly big improvement in memory usage and execution time for 24 hour linked
  shows (memory usage no longer grows with show length)
This commit is contained in:
Albert Santoni 2014-08-15 18:17:23 -04:00
parent 7bd443f668
commit 60f4d112e7
2 changed files with 132 additions and 93 deletions

View File

@ -281,6 +281,14 @@ class CcShow extends BaseCcShow {
return $instanceIds; return $instanceIds;
} }
public function getFutureInstanceIds() {
$instanceIds = array();
foreach ($this->getFutureCcShowInstancess() as $ccShowInstance) {
$instanceIds[] = $ccShowInstance->getDbId();
}
return $instanceIds;
}
public function getOtherInstances($instanceId) public function getOtherInstances($instanceId)
{ {
return CcShowInstancesQuery::create() return CcShowInstancesQuery::create()

View File

@ -161,12 +161,26 @@ class Application_Service_SchedulerService
return; return;
} }
$schedule_sql = "SELECT * FROM cc_schedule ". $doesAnyShowInstanceHaveContent = false;
"WHERE instance_id IN (".implode($instanceIds, ",").")"; foreach ($instanceIds as $instanceId)
{
$schedule_sql = "SELECT instance_id FROM cc_schedule ".
"WHERE instance_id=$instanceId";//#IN (".implode($instanceIds, ",").")";
$ccSchedules = Application_Common_Database::prepareAndExecute( $ccSchedules = Application_Common_Database::prepareAndExecute(
$schedule_sql); $schedule_sql);
if (count($ccSchedules) > 0) { if (count($ccSchedules) > 0) {
$doesAnyShowInstanceHaveContent = true;
break;
}
}
if ($doesAnyShowInstanceHaveContent == false)
{
//The linked shows are all empty, so there's nothing for us to do.
//(No content should be propagated to the other show instances...
return;
}
/* Find the show contents of just one of the instances. It doesn't /* Find the show contents of just one of the instances. It doesn't
* matter which instance we use since all the content is the same * matter which instance we use since all the content is the same
*/ */
@ -185,10 +199,16 @@ class Application_Service_SchedulerService
//need to find out which linked instances are empty //need to find out which linked instances are empty
$values = array(); $values = array();
foreach ($instanceIds as $id) { $futureInstanceIds = $ccShow->getFutureInstanceIds();
$con = Propel::getConnection();
try {
$con->beginTransaction();
foreach ($instanceIds as $id)
{
$instanceSched_sql = "SELECT * FROM cc_schedule ". $instanceSched_sql = "SELECT * FROM cc_schedule ".
"WHERE instance_id = {$id} ". "WHERE instance_id = {$id} ".
"ORDER by starts"; "ORDER by starts";
$ccSchedules = Application_Common_Database::prepareAndExecute( $ccSchedules = Application_Common_Database::prepareAndExecute(
$instanceSched_sql); $instanceSched_sql);
@ -197,7 +217,8 @@ class Application_Service_SchedulerService
* (The show stamp is taken from the first show instance's content) * (The show stamp is taken from the first show instance's content)
*/ */
if (count($ccSchedules) < 1 || if (count($ccSchedules) < 1 ||
self::replaceInstanceContentCheck($ccSchedules, $showStamp)) { self::replaceInstanceContentCheck($ccSchedules, $showStamp))
{
$instanceStart_sql = "SELECT starts FROM cc_show_instances ". $instanceStart_sql = "SELECT starts FROM cc_show_instances ".
"WHERE id = {$id} ". "WHERE id = {$id} ".
@ -207,6 +228,9 @@ class Application_Service_SchedulerService
$instanceStart_sql, array(), Application_Common_Database::COLUMN), $instanceStart_sql, array(), Application_Common_Database::COLUMN),
new DateTimeZone("UTC")); new DateTimeZone("UTC"));
$defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration();
unset($values);
$values = array();
foreach ($showStamp as $item) { foreach ($showStamp as $item) {
$endTimeDT = self::findEndTime($nextStartDT, $item["clip_length"]); $endTimeDT = self::findEndTime($nextStartDT, $item["clip_length"]);
@ -231,10 +255,9 @@ class Application_Service_SchedulerService
"{$item["position"]})"; "{$item["position"]})";
$nextStartDT = self::findTimeDifference($endTimeDT, $nextStartDT = self::findTimeDifference($endTimeDT,
Application_Model_Preference::GetDefaultCrossfadeDuration()); $defaultCrossfadeDuration);
} //foreach show item } //foreach show item
}
} //foreach linked instance
if (!empty($values)) { if (!empty($values)) {
$insert_sql = "INSERT INTO cc_schedule (starts, ends, ". $insert_sql = "INSERT INTO cc_schedule (starts, ends, ".
@ -244,6 +267,9 @@ class Application_Service_SchedulerService
Application_Common_Database::prepareAndExecute( Application_Common_Database::prepareAndExecute(
$insert_sql, array(), Application_Common_Database::EXECUTE); $insert_sql, array(), Application_Common_Database::EXECUTE);
}
}
} //foreach linked instance
//update time_filled in cc_show_instances //update time_filled in cc_show_instances
$now = gmdate("Y-m-d H:i:s"); $now = gmdate("Y-m-d H:i:s");
@ -253,9 +279,14 @@ class Application_Service_SchedulerService
"WHERE show_id = {$ccShow->getDbId()}"; "WHERE show_id = {$ccShow->getDbId()}";
Application_Common_Database::prepareAndExecute( Application_Common_Database::prepareAndExecute(
$update_sql, array(), Application_Common_Database::EXECUTE); $update_sql, array(), Application_Common_Database::EXECUTE);
}
} //if at least one linked instance has content $con->commit();
Logging::info("finished fill");
} catch (Exception $e) {
$con->rollback();
Logging::info("Error filling linked shows: ".$e->getMessage());
exit();
}
} }
public static function fillPreservedLinkedShowContent($ccShow, $showStamp) public static function fillPreservedLinkedShowContent($ccShow, $showStamp)