getRedis(); $key = $this->getSyncKey(); $questionIds = $redis->sRandMember($key, 1000); if (!$questionIds) return; $questionRepo = new QuestionRepo(); $questions = $questionRepo->findByIds($questionIds); if ($questions->count() == 0) return; $document = new QuestionDocument(); $handler = new QuestionSearcher(); $index = $handler->getXS()->getIndex(); $index->openBuffer(); foreach ($questions as $question) { $doc = $document->setDocument($question); if ($question->published == QuestionModel::PUBLISH_APPROVED) { $index->update($doc); } else { $index->del($question->id); } } $index->closeBuffer(); $redis->sRem($key, ...$questionIds); } protected function getSyncKey() { $sync = new QuestionIndexSync(); return $sync->getSyncKey(); } }