Skip to content

Instantly share code, notes, and snippets.

@firecentaur
Created May 28, 2020 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firecentaur/0592d0b13ea08ef4f1ac9ecdec855572 to your computer and use it in GitHub Desktop.
Save firecentaur/0592d0b13ea08ef4f1ac9ecdec855572 to your computer and use it in GitHub Desktop.
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