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:
parent
7bd443f668
commit
60f4d112e7
|
@ -281,6 +281,14 @@ class CcShow extends BaseCcShow {
|
|||
return $instanceIds;
|
||||
}
|
||||
|
||||
public function getFutureInstanceIds() {
|
||||
$instanceIds = array();
|
||||
foreach ($this->getFutureCcShowInstancess() as $ccShowInstance) {
|
||||
$instanceIds[] = $ccShowInstance->getDbId();
|
||||
}
|
||||
return $instanceIds;
|
||||
}
|
||||
|
||||
public function getOtherInstances($instanceId)
|
||||
{
|
||||
return CcShowInstancesQuery::create()
|
||||
|
|
|
@ -161,12 +161,26 @@ class Application_Service_SchedulerService
|
|||
return;
|
||||
}
|
||||
|
||||
$schedule_sql = "SELECT * FROM cc_schedule ".
|
||||
"WHERE instance_id IN (".implode($instanceIds, ",").")";
|
||||
$doesAnyShowInstanceHaveContent = false;
|
||||
foreach ($instanceIds as $instanceId)
|
||||
{
|
||||
$schedule_sql = "SELECT instance_id FROM cc_schedule ".
|
||||
"WHERE instance_id=$instanceId";//#IN (".implode($instanceIds, ",").")";
|
||||
$ccSchedules = Application_Common_Database::prepareAndExecute(
|
||||
$schedule_sql);
|
||||
|
||||
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
|
||||
* 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
|
||||
$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 ".
|
||||
"WHERE instance_id = {$id} ".
|
||||
"ORDER by starts";
|
||||
|
||||
$ccSchedules = Application_Common_Database::prepareAndExecute(
|
||||
$instanceSched_sql);
|
||||
|
||||
|
@ -197,7 +217,8 @@ class Application_Service_SchedulerService
|
|||
* (The show stamp is taken from the first show instance's content)
|
||||
*/
|
||||
if (count($ccSchedules) < 1 ||
|
||||
self::replaceInstanceContentCheck($ccSchedules, $showStamp)) {
|
||||
self::replaceInstanceContentCheck($ccSchedules, $showStamp))
|
||||
{
|
||||
|
||||
$instanceStart_sql = "SELECT starts FROM cc_show_instances ".
|
||||
"WHERE id = {$id} ".
|
||||
|
@ -207,6 +228,9 @@ class Application_Service_SchedulerService
|
|||
$instanceStart_sql, array(), Application_Common_Database::COLUMN),
|
||||
new DateTimeZone("UTC"));
|
||||
|
||||
$defaultCrossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration();
|
||||
unset($values);
|
||||
$values = array();
|
||||
foreach ($showStamp as $item) {
|
||||
$endTimeDT = self::findEndTime($nextStartDT, $item["clip_length"]);
|
||||
|
||||
|
@ -231,10 +255,9 @@ class Application_Service_SchedulerService
|
|||
"{$item["position"]})";
|
||||
|
||||
$nextStartDT = self::findTimeDifference($endTimeDT,
|
||||
Application_Model_Preference::GetDefaultCrossfadeDuration());
|
||||
$defaultCrossfadeDuration);
|
||||
|
||||
} //foreach show item
|
||||
}
|
||||
} //foreach linked instance
|
||||
|
||||
if (!empty($values)) {
|
||||
$insert_sql = "INSERT INTO cc_schedule (starts, ends, ".
|
||||
|
@ -244,6 +267,9 @@ class Application_Service_SchedulerService
|
|||
|
||||
Application_Common_Database::prepareAndExecute(
|
||||
$insert_sql, array(), Application_Common_Database::EXECUTE);
|
||||
}
|
||||
}
|
||||
} //foreach linked instance
|
||||
|
||||
//update time_filled in cc_show_instances
|
||||
$now = gmdate("Y-m-d H:i:s");
|
||||
|
@ -253,9 +279,14 @@ class Application_Service_SchedulerService
|
|||
"WHERE show_id = {$ccShow->getDbId()}";
|
||||
Application_Common_Database::prepareAndExecute(
|
||||
$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)
|
||||
|
|
Loading…
Reference in New Issue