Skip to content
Snippets Groups Projects
Commit 716d3174 authored by André Lahmann's avatar André Lahmann Committed by Demian Katz
Browse files

Fixes shard support for retrieveBatch

- fixes bugs when retrieving multiple records (e.g. in Cart/Home)
parent b4ccf26e
No related merge requests found
......@@ -116,9 +116,10 @@ class MultiIndexListener
$backend = $event->getTarget();
if ($backend === $this->backend) {
$params = $event->getParam('params');
if ($event->getParam('context') == 'retrieve') {
// If we're retrieving a record, we should pull all shards to be
// sure we find it.
$allShardsContexts = ['retrieve', 'retrieveBatch'];
if (in_array($event->getParam('context'), $allShardsContexts)) {
// If we're retrieving by id(s), we should pull all shards to be
// sure we find the right record(s).
$params->set('shards', implode(',', $this->shards));
} else {
// In any other context, we should make sure our field values are
......
......@@ -163,6 +163,8 @@ class Backend extends AbstractBackend
*/
public function retrieveBatch($ids, ParamBag $params = null)
{
$params = $params ?: new ParamBag();
// Load 100 records at a time; this is a good number to avoid memory
// problems while still covering a lot of ground.
$pageSize = 100;
......@@ -177,13 +179,9 @@ class Backend extends AbstractBackend
while (count($ids) > 0) {
$currentPage = array_splice($ids, 0, $pageSize, []);
$currentPage = array_map($formatIds, $currentPage);
$params = new ParamBag(
[
'q' => 'id:(' . implode(' OR ', $currentPage) . ')',
'start' => 0,
'rows' => $pageSize
]
);
$params->set('q', 'id:(' . implode(' OR ', $currentPage) . ')');
$params->set('start', 0);
$params->set('rows', $pageSize);
$this->injectResponseWriter($params);
$next = $this->createRecordCollection(
$this->connector->search($params)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment