Skip to content

Commit 4122acf

Browse files
committed
integrated identity map into insert mechanism
- if entity exists in identity map with that id/index combination it is returned instead of getting it from Elasticsearch - after entity is inserted to elasticsearch, that entity is also stored in identitymap
1 parent eb1f2f5 commit 4122acf

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/Model/Insert.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public function __construct(
99
private \Spameri\Elastic\Model\Insert\PrepareEntityArray $prepareEntityArray,
1010
private \Spameri\Elastic\ClientProvider $clientProvider,
11-
private \Spameri\Elastic\Model\VersionProvider $versionProvider,
11+
private \Spameri\Elastic\Model\IdentityMap $identityMap,
1212
)
1313
{
1414
}
@@ -27,6 +27,10 @@ public function execute(
2727
$entityArray = $this->prepareEntityArray->prepare($entity, $hasSti);
2828
unset($entityArray['id']);
2929

30+
if ($this->identityMap->isChanged($entity) === false) {
31+
return $entity->id()->value();
32+
}
33+
3034
try {
3135
$response = $this->clientProvider->client()->index(
3236
(
@@ -58,6 +62,8 @@ public function execute(
5862

5963
if (isset($response['result']) && ($response['result'] === 'created' || $response['result'] === 'updated')) {
6064
$entity->id = new \Spameri\Elastic\Entity\Property\ElasticId($response['_id']);
65+
$this->identityMap->markInserted($entity);
66+
6167
return $response['_id'];
6268
}
6369

0 commit comments

Comments
 (0)