From ba9f7879a47444751ca73edb4f259b9affbe1866 Mon Sep 17 00:00:00 2001 From: Robb Ebright Date: Sun, 12 Mar 2017 22:36:36 -0400 Subject: [PATCH] modified smart block to not exceed the time limits. --- airtime_mvc/application/models/Block.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 21023e629..d07a636f0 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1310,10 +1310,18 @@ SQL; $id = $iterator->current()->getDbId(); $fileLength = $iterator->current()->getCueLength(); $length = Application_Common_DateHelper::calculateLengthInSeconds($fileLength); - $insertList[] = array('id'=>$id, 'length'=>$length); - $totalTime += $length; - $totalItems++; - + // need to check to determine if the track will make the playlist exceed the totalTime before adding it + // this can be quite processor consuming so as a workaround I used the totalItems limit to prevent the + // algorithm from parsing too many items. + $projectedTime = $totalTime + $length; + if ($projectedTime > $limit['time']) { + $totalItems++; + } + else { + $insertList[] = array('id' => $id, 'length' => $length); + $totalTime += $length; + $totalItems++; + } if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) { $isBlockFull = true; break;