コード例 #1
0
ファイル: Publish.php プロジェクト: xtrasmal/iinano
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln("Fill...");
     $cardinal = $input->getArgument('count');
     $seed = sha1(microtime() . rand() . $cardinal);
     /* @var $progressBar \Symfony\Component\Console\Helper\ProgressHelper */
     $progressBar = $this->getHelper('progress');
     /* @var $repo \Trismegiste\Yuurei\Persistence\RepositoryInterface */
     $repo = $this->getContainer()->get('dokudoki.repository');
     $netizenList = iterator_to_array($repo->find(['-class' => 'netizen']), false);
     $netizenCount = count($netizenList);
     $progressBar->start($output, $cardinal);
     for ($k = 0; $k < $cardinal; $k++) {
         /* @var $picked \Trismegiste\SocialBundle\Security\Netizen */
         $picked = $netizenList[rand(0, $netizenCount - 1)];
         $pub = new \Trismegiste\Socialist\SmallTalk($picked->getAuthor());
         $pub->setMessage("This is a not so short message ({$seed}) to fill the database for benchmark purpose");
         foreach ($picked->getFanIterator() as $fan => $dummy) {
             $tmpAuth = new \Trismegiste\Socialist\Author($fan);
             $pub->addFan($tmpAuth);
         }
         $repo->persist($pub);
         $progressBar->advance();
     }
     $progressBar->finish();
 }
コード例 #2
0
ファイル: CliqueBench.php プロジェクト: xtrasmal/iinano
 protected function fill(OutputInterface $output, $numUser, $msgPerUser)
 {
     /* @var $userRepo \Trismegiste\SocialBundle\Repository\NetizenRepository */
     $userRepo = $this->getContainer()->get('social.netizen.repository');
     /* @var $userFactory \Trismegiste\SocialBundle\Security\NetizenFactory */
     $userFactory = $this->getContainer()->get('security.netizen.factory');
     /* @var $contentRepo \Trismegiste\Yuurei\Persistence\Repository */
     $contentRepo = $this->getContainer()->get('dokudoki.repository');
     /* @var $progressBar \Symfony\Component\Console\Helper\ProgressHelper */
     $progressBar = $this->getHelper('progress');
     $output->writeln("With {$numUser} Users");
     $progressBar->start($output, $numUser * 3);
     for ($k = 0; $k < $numUser; $k++) {
         $user[$k] = $userFactory->create("iinano-netizen-{$k}", 'aaaa');
         $progressBar->advance();
     }
     // follow & like user
     for ($k = 0; $k < $numUser; $k++) {
         for ($j = 0; $j < $numUser; $j++) {
             $user[$k]->follow($user[$j]);
             $user[$k]->addFan($user[$j]->getAuthor());
         }
         $progressBar->advance();
     }
     for ($k = 0; $k < $numUser; $k++) {
         $userRepo->persist($user[$k]);
         $progressBar->advance();
     }
     $progressBar->finish();
     // message
     $output->writeln("Writing message");
     $progressBar->start($output, $numUser * $msgPerUser);
     for ($k = 0; $k < $numUser; $k++) {
         $batch = [];
         $author = $user[$k]->getAuthor();
         // template for one author :
         $docTemplate = new \Trismegiste\Socialist\SmallTalk($author);
         for ($i = 0; $i < $numUser; $i++) {
             $docTemplate->addFan($user[$i]->getAuthor());
         }
         for ($i = 0; $i < 10; $i++) {
             $comm = new \Trismegiste\Socialist\Commentary($user[rand(0, $numUser - 1)]->getAuthor());
             $comm->setMessage('This is not a very long commentary but I think it is a good approx');
             $docTemplate->attachCommentary($comm);
         }
         for ($j = 0; $j < $msgPerUser; $j++) {
             $doc = clone $docTemplate;
             $doc->setMessage("One small talk {$k}-{$j} for iinano benchmark, one giant doc for mongo but it's not a big deal for this database");
             $batch[] = $doc;
             //$contentRepo->persist($doc);
             $progressBar->advance();
         }
         $contentRepo->batchPersist($batch);
     }
     $progressBar->finish();
 }