public function getDocuments(array $idList, $callable = null)
{
$idListToFindDirectly = $idList;
// try to egt document from pool if enabled
$documentsInDocumentPool = array();
if ($this->isDocumentPoolEnabled() && !$callable) {
$documentsInDocumentPool = $this->getDocumentsFromDocumentPool($idList);
if (count($documentsInDocumentPool) === count($idList)) {
return $documentsInDocumentPool;
}
// skip ids already found in pool
$idListToFindDirectly = array_diff_key(array_map('strval', $idList), array_keys($documentsInDocumentPool));
}
// get documents directly
$cursor = $this->find();
if (is_callable($callable)) {
call_user_func($callable, $cursor);
}
$documentsGettingDirectly = $cursor->byIdList($idListToFindDirectly)->findAll();
if (!$documentsGettingDirectly) {
return $documentsInDocumentPool ? $documentsInDocumentPool : array();
}
if ($this->isDocumentPoolEnabled()) {
$this->addDocumentsToDocumentPool($documentsGettingDirectly);
}
return $documentsGettingDirectly + $documentsInDocumentPool;
}