Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit fe3e9a8

Browse files
authored
Fix delete to use refresh option (#301)
1 parent c629b3e commit fe3e9a8

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

src/Indexers/BulkIndexer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public function delete(Collection $models)
6969
$bulkPayload->add('body', $actionPayload->get());
7070
});
7171

72+
if ($documentRefresh = config('scout_elastic.document_refresh')) {
73+
$bulkPayload->set('refresh', $documentRefresh);
74+
}
75+
7276
$bulkPayload->set('client.ignore', 404);
7377

7478
ElasticClient::bulk($bulkPayload->get());

src/Indexers/SingleIndexer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ public function update(Collection $models)
5151
public function delete(Collection $models)
5252
{
5353
$models->each(function ($model) {
54-
$payload = (new DocumentPayload($model))
55-
->set('client.ignore', 404)
56-
->get();
54+
$payload = new DocumentPayload($model);
55+
56+
57+
if ($documentRefresh = config('scout_elastic.document_refresh')) {
58+
$payload->set('refresh', $documentRefresh);
59+
}
60+
61+
$payload->set('client.ignore', 404);
5762

58-
ElasticClient::delete($payload);
63+
ElasticClient::delete($payload->get());
5964
});
6065
}
6166
}

tests/Indexers/BulkIndexerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,31 @@ public function testDelete()
106106

107107
$this->addToAssertionCount(1);
108108
}
109+
110+
public function testDeleteWithSpecifiedDocumentRefreshOption()
111+
{
112+
Config::set('scout_elastic.document_refresh', true);
113+
114+
ElasticClient
115+
::shouldReceive('bulk')
116+
->once()
117+
->with([
118+
'index' => 'test',
119+
'type' => 'test',
120+
'body' => [
121+
['delete' => ['_id' => 1]],
122+
['delete' => ['_id' => 2]],
123+
['delete' => ['_id' => 3]],
124+
],
125+
'refresh' => true,
126+
'client' => [
127+
'ignore' => 404,
128+
],
129+
]);
130+
131+
(new BulkIndexer())
132+
->delete($this->models);
133+
134+
$this->addToAssertionCount(1);
135+
}
109136
}

tests/Indexers/SingleIndexerTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,49 @@ public function testDelete()
157157

158158
$this->addToAssertionCount(1);
159159
}
160+
161+
public function testDeleteWithSpecifiedDocumentRefreshOption()
162+
{
163+
Config::set('scout_elastic.document_refresh', true);
164+
165+
ElasticClient
166+
::shouldReceive('delete')
167+
->once()
168+
->with([
169+
'index' => 'test',
170+
'type' => 'test',
171+
'id' => 1,
172+
'refresh' => true,
173+
'client' => [
174+
'ignore' => 404,
175+
],
176+
])
177+
->shouldReceive('delete')
178+
->once()
179+
->with([
180+
'index' => 'test',
181+
'type' => 'test',
182+
'id' => 2,
183+
'refresh' => true,
184+
'client' => [
185+
'ignore' => 404,
186+
],
187+
])
188+
->shouldReceive('delete')
189+
->once()
190+
->with([
191+
'index' => 'test',
192+
'type' => 'test',
193+
'id' => 3,
194+
'refresh' => true,
195+
'client' => [
196+
'ignore' => 404,
197+
],
198+
]);
199+
200+
(new SingleIndexer())
201+
->delete($this->models);
202+
203+
$this->addToAssertionCount(1);
204+
}
160205
}

0 commit comments

Comments
 (0)