/** * */ public function testFind() { if (extension_loaded('xdebug')) { $this->assertTrue(true); return; } $gameVersion = 'tw'; $pool = PdoFactory::makePool($gameVersion); $uidList = [474000, 474001, 474002]; $provider = new UserDetailProvider($gameVersion, $pool); $payload = array_filter($provider->find($uidList)); $foundUidList = []; foreach ($payload as $shardId => $userList) { static::assertStringStartsWith('db', $shardId); $foundUidList = array_merge($foundUidList, array_keys($userList)); foreach ($userList as $user) { static::assertTrue(is_array($user)); static::assertArrayHasKey('uid', $user); static::assertArrayHasKey('snsid', $user); static::assertArrayHasKey('history_pay_amount', $user); } } sort($uidList); sort($foundUidList); static::assertEquals($uidList, $foundUidList); }
/** * @param array $groupedUidList * * @return int */ public function updateES(array $groupedUidList) { appendLog(sprintf('%s start with memory usage %s', __METHOD__, PHP_Timer::resourceUsage())); $count = array_sum(array_map(function (array $list) { return count($list); }, $groupedUidList)); if ($count === 0) { appendLog(sprintf('%s: have 0 user to sync', __METHOD__)); return 0; } $start = microtime(true); $groupedDetail = $this->dataProvider->generate($groupedUidList); $delta = microtime(true) - $start; $totalUidCount = array_sum(array_map(function (array $uidList) { return count($uidList); }, $groupedUidList)); appendLog(sprintf('Total %d uids, read detail cost %s', $totalUidCount, PHP_Timer::secondsToTimeString($delta))); $bufferSyncAction = function (array $users) { $count = count($users); appendLog(sprintf('ES updater have %d user to sync', $count)); $deltaList = $this->indexer->batchUpdate($users, function ($userCount, $delta) { appendLog(sprintf('on ES batch update of %d users cost %s', $userCount, PHP_Timer::secondsToTimeString($delta))); }); $totalDelta = array_sum($deltaList); appendLog(sprintf('Sync %d users to ES cost %s with average cost %s', $count, PHP_Timer::secondsToTimeString($totalDelta), PHP_Timer::secondsToTimeString($totalDelta / $count))); }; $buffer = new WriteBuffer($bufferSyncAction, 500); foreach ($groupedDetail as $payload) { $shardId = $payload['shardId']; $shardUserList = $payload['dataSet']; $count = count($shardUserList); if ($count === 0) { continue; } appendLog(sprintf('%s have %d user to sync', $shardId, $count)); foreach ($shardUserList as $userInfo) { $buffer->add($userInfo); } } $buffer->sync(); }
} return $filePath; }; $fromDate = date_create_from_format('Ymd', $fromDay); if (!$fromDate instanceof \DateTime) { appendLog(sprintf('from [%s] not valid', $fromDay)); return; } $toDate = date_create_from_format('Ymd', $toDay); if (!$toDate instanceof \DateTime) { appendLog(sprintf('to [%s] not valid', $toDay)); return; } $pdoPool = PdoFactory::makePool($gameVersion); $installUidProvider = new InstallUidProvider($gameVersion, $pdoPool); $userDetailProvider = new UserDetailProvider($gameVersion, $pdoPool); $magicNumber = isset($options['magic']) ? (int) $options['magic'] : 500; assert($magicNumber > 10); $indexer = IndexerFactory::make(ELASTIC_SEARCH_HOST, $gameVersion, $magicNumber); if ($verbose) { dump(sprintf('version: %s, from: %s, to: %s, safe: %d, magic: %d', $gameVersion, $fromDay, $toDay, $safeRound, $magicNumber)); } $calendarDayGenerator = CalendarDayGenerator::generate($fromDate->getTimestamp(), $toDate->getTimestamp()); $totalUser = 0; $processedRound = 0; foreach ($calendarDayGenerator as $calendarDay) { $markerDate = new DateTimeImmutable($calendarDay); if ($calendarMarker->isMarked($markerDate)) { appendLog('bypass ' . $markerDate->format('Y-m-d')); continue; }
require __DIR__ . '/../../bootstrap.php'; $options = getopt('v', ['gv:', 'es:', 'uid:']); $verbose = isset($options['v']); $gameVersion = null; if (defined('GAME_VERSION')) { $gameVersion = GAME_VERSION; } else { assert(isset($options['gv']), 'game version not defined'); $gameVersion = trim($options['gv']); } $esHost = isset($options['es']) ? $options['es'] : '52.19.73.190'; assert(isset($options['uid']), 'uid not defined'); $uid = trim($options['uid']); $msg = sprintf('game version: %s, ES host: %s, uid: %s', $gameVersion, $esHost, $uid); $verbose && dump($msg); $provider = new UserDetailProvider($gameVersion, PdoFactory::makePool($gameVersion)); $groupedUserList = array_filter($provider->find([$uid])); if ($verbose) { dump(__FILE__); dump($groupedUserList); } $indexer = IndexerFactory::make($esHost, $gameVersion); foreach ($groupedUserList as $shardId => $shardUserList) { $delta = $indexer->batchUpdate($shardUserList); $batchResult = $indexer->getBatchResult(); dump(__FILE__); array_map(function ($errorString) { $decoded = json_decode($errorString, true); if (is_array($decoded)) { dump($decoded); } else {