Skip to content

Commit a43e72d

Browse files
committed
(fix): use document tenant for upsertDocuments key construction
1 parent a0d5efc commit a43e72d

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/Database/Adapter/Redis.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,18 +2311,19 @@ public function upsertDocuments(
23112311
}
23122312

23132313
$col = $this->filter($collection->getId());
2314-
$idxKey = $this->idxKey($col);
2315-
$seqKey = $this->seqKey($col);
23162314

2317-
return $this->tx(function (RedisClient $redis) use ($col, $attribute, $changes, $idxKey, $seqKey): array {
2315+
return $this->tx(function (RedisClient $redis) use ($col, $attribute, $changes): array {
23182316
$results = [];
23192317

23202318
// Phase 1: pipeline GETs of every doc so we know create vs update
2321-
// in a single round trip.
2319+
// in a single round trip. Mirror createDocument and route every
2320+
// doc/idx/seq key through the document's own tenant so a batch
2321+
// that mixes tenants under shared tables doesn't silently
2322+
// misroute to the adapter-bound bucket.
23222323
$redis->multi(\Redis::PIPELINE);
23232324
foreach ($changes as $change) {
23242325
$document = $change->getNew();
2325-
$redis->get($this->docKey($col, $document->getId()));
2326+
$redis->get($this->docKey($col, $document->getId(), $document->getTenant()));
23262327
}
23272328
$existingPayloads = $redis->exec();
23282329
if (! \is_array($existingPayloads)) {
@@ -2342,7 +2343,10 @@ public function upsertDocuments(
23422343
foreach ($changes as $i => $change) {
23432344
$document = $change->getNew();
23442345
$id = $document->getId();
2345-
$docKey = $this->docKey($col, $id);
2346+
$tenant = $document->getTenant();
2347+
$docKey = $this->docKey($col, $id, $tenant);
2348+
$idxKey = $this->idxKey($col, $tenant);
2349+
$seqKey = $this->seqKey($col, $tenant);
23462350
$existingPayload = $existingPayloads[$i] ?? false;
23472351

23482352
if (\is_string($existingPayload) && $existingPayload !== '') {

0 commit comments

Comments
 (0)