CC-4639: Give an option to allow smart blocks to reuse tracks if not enough

tracks meet the time limit

- code optimazation
This commit is contained in:
james 2012-10-31 12:05:17 -04:00
parent 1899d588ee
commit 9293a26738
2 changed files with 13 additions and 16 deletions

View file

@ -513,7 +513,7 @@ class PlaylistController extends Zend_Controller_Action
} catch (BlockNotFoundException $e) { } catch (BlockNotFoundException $e) {
$this->playlistNotFound('block', true); $this->playlistNotFound('block', true);
} catch (Exception $e) { } catch (Exception $e) {
Logging::info($e); //Logging::info($e);
$this->playlistUnknownError($e); $this->playlistUnknownError($e);
} }
} }

View file

@ -1113,7 +1113,12 @@ SQL;
$this->saveSmartBlockCriteria($p_criteria); $this->saveSmartBlockCriteria($p_criteria);
$insertList = $this->getListOfFilesUnderLimit(); $insertList = $this->getListOfFilesUnderLimit();
$this->deleteAllFilesFromBlock(); $this->deleteAllFilesFromBlock();
$this->addAudioClips(array_values($insertList)); // constrcut id array
$ids = array();
foreach ($insertList as $ele) {
$ids[] = $ele['id'];
}
$this->addAudioClips(array_values($ids));
// update length in playlist contents. // update length in playlist contents.
$this->updateBlockLengthInAllPlaylist(); $this->updateBlockLengthInAllPlaylist();
@ -1157,7 +1162,7 @@ SQL;
while ($iterator->valid()) { while ($iterator->valid()) {
$id = $iterator->current()->getDbId(); $id = $iterator->current()->getDbId();
$length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength()); $length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
$insertList[] = $id; $insertList[] = array('id'=>$id, 'length'=>$length);
$totalTime += $length; $totalTime += $length;
$totalItems++; $totalItems++;
@ -1169,26 +1174,18 @@ SQL;
$iterator->next(); $iterator->next();
} }
$sizeOfInsert = count($insertList);
// if block is not full and reapeat_track is check, fill up more // if block is not full and reapeat_track is check, fill up more
while (!$isBlockFull && $repeat == 1) { while (!$isBlockFull && $repeat == 1) {
if (!$iterator->valid()) { $randomEleKey = array_rand(array_slice($insertList, 0, $sizeOfInsert));
$iterator->closeCursor(); $insertList[] = $insertList[$randomEleKey];
$info = $this->getListofFilesMeetCriteria(); $totalTime += $insertList[$randomEleKey]['length'];
$files = $info['files'];
$files->getFirst();
$iterator = $files->getIterator();
}
$id = $iterator->current()->getDbId();
$length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
$insertList[] = $id;
$totalTime += $length;
$totalItems++; $totalItems++;
if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) { if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) {
break; break;
} }
$iterator->next();
} }
return $insertList; return $insertList;