Created
May 28, 2020 00:30
-
-
Save firecentaur/0592d0b13ea08ef4f1ac9ecdec855572 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function actionBulk() | |
{ | |
/* | |
* Due to less data, dcouments are inserted one by one, otherwise we will change it to bulk insert. | |
*/ | |
$c = new CDbCriteria(); | |
$c->addCondition("status is null"); | |
/** | |
* @var $videos | |
* $videos VideoLibraryVideo[] | |
*/ | |
$videos = Video::model()->findAll($c); | |
$total = count($videos); | |
$videosIndex = Yii::app()->params['videosIndex']; | |
echo "\nIndexing $total Videos into $videosIndex\n"; | |
/** | |
* @var $video | |
* $videos VideoLibraryVideo | |
*/ | |
$videoSearch = new VideoSearch(); | |
foreach ($videos as $index => $video) { | |
$videos[] = VideoSearch::getVideoMapData($video); | |
} | |
$numVideos = count($videos); | |
$chunkSize=250; | |
$videoChunks = array_chunk($videos,$chunkSize); | |
$totalChunks = count($videoChunks); | |
foreach ($videoChunks as $index => $chunk) { | |
$percentage = floor($index/$totalChunks*100); | |
$message="\n$percentage% complete $index of $total groups of $chunkSize videos."; | |
echo $message; | |
$videoSearch->indexVideosBulk($chunk); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment