From eae1b4e17ce76ad6d70ba9c79c143ff4f121a98f Mon Sep 17 00:00:00 2001 From: drigato Date: Tue, 28 Oct 2014 10:25:40 -0400 Subject: [PATCH 1/2] CC-5932: Update is_scheduled query is too slow --- airtime_mvc/application/models/StoredFile.php | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 009572647..8b2d92773 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -1368,27 +1368,44 @@ SQL; return $updateIsScheduled; } + /** + * + * Updates the is_scheduled flag to false for tracks that are no longer + * scheduled in the future. We do this by checking the difference between + * all files scheduled in the future and all files with is_scheduled = true. + * The difference of the two result sets is what we need to update. + */ public static function updatePastFilesIsScheduled() { - /* Set the is_scheduled flag to false where it was true in the - * past, and where tracks are not scheduled in the future and do - * not belong to a show that has not ended yet. We need to check - * for show end times in case a track is overbooked, which would - * indicate it is still scheduled in the future - */ - $sql = << now() at time zone 'UTC' - AND i.ends > now() at time zone 'UTC' -) -SQL; - Application_Common_Database::prepareAndExecute($sql, array(), - Application_Common_Database::EXECUTE); + $futureScheduledFilesSelectCriteria = new Criteria(); + $futureScheduledFilesSelectCriteria->addSelectColumn(CcSchedulePeer::FILE_ID); + $futureScheduledFilesSelectCriteria->setDistinct(); + $futureScheduledFilesSelectCriteria->add(CcSchedulePeer::ENDS, gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN); + $stmt = CcSchedulePeer::doSelectStmt($futureScheduledFilesSelectCriteria); + $filesScheduledInFuture = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); + $count = 0; + foreach ($filesScheduledInFuture as $f) { + $count += 1; + } + + $filesCurrentlySetWithIsScheduledSelectCriteria = new Criteria(); + $filesCurrentlySetWithIsScheduledSelectCriteria->addSelectColumn(CcFilesPeer::ID); + $filesCurrentlySetWithIsScheduledSelectCriteria->add(CcFilesPeer::IS_SCHEDULED, true); + $stmt = CcFilesPeer::doSelectStmt($filesCurrentlySetWithIsScheduledSelectCriteria); + $filesCurrentlySetWithIsScheduled = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); + $count = 0; + foreach ($filesCurrentlySetWithIsScheduled as $t) { + $count += 1; + } + + $diff = array_diff($filesCurrentlySetWithIsScheduled, $filesScheduledInFuture); + + $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME); + $selectCriteria = new Criteria(); + $selectCriteria->add(CcFilesPeer::ID, $diff, Criteria::IN); + $updateCriteria = new Criteria(); + $updateCriteria->add(CcFilesPeer::IS_SCHEDULED, false); + BasePeer::doUpdate($selectCriteria, $updateCriteria, $con); } } From 1d3180cc806d6bad552aa3b649d092a62b4e828a Mon Sep 17 00:00:00 2001 From: drigato Date: Tue, 28 Oct 2014 10:29:25 -0400 Subject: [PATCH 2/2] CC-5932: Update is_scheduled query is too slow Forgot to remove some debugging statements --- airtime_mvc/application/models/StoredFile.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 8b2d92773..2c97d41d3 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -1383,20 +1383,12 @@ SQL; $futureScheduledFilesSelectCriteria->add(CcSchedulePeer::ENDS, gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN); $stmt = CcSchedulePeer::doSelectStmt($futureScheduledFilesSelectCriteria); $filesScheduledInFuture = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); - $count = 0; - foreach ($filesScheduledInFuture as $f) { - $count += 1; - } $filesCurrentlySetWithIsScheduledSelectCriteria = new Criteria(); $filesCurrentlySetWithIsScheduledSelectCriteria->addSelectColumn(CcFilesPeer::ID); $filesCurrentlySetWithIsScheduledSelectCriteria->add(CcFilesPeer::IS_SCHEDULED, true); $stmt = CcFilesPeer::doSelectStmt($filesCurrentlySetWithIsScheduledSelectCriteria); $filesCurrentlySetWithIsScheduled = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); - $count = 0; - foreach ($filesCurrentlySetWithIsScheduled as $t) { - $count += 1; - } $diff = array_diff($filesCurrentlySetWithIsScheduled, $filesScheduledInFuture);