Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix custom scout keys not being utilized when deleting from queue #657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1959292
Add getUnqualifiedScoutKeyName method
stevebauman Sep 30, 2022
6146bb7
Add RemoveableScoutCollection tests
stevebauman Sep 30, 2022
071c9de
Change order of update indexing so a custom key cannot be overridden …
stevebauman Sep 30, 2022
d996a04
Return a RemoveableScoutCollection instance and fix key type when sco…
stevebauman Sep 30, 2022
73227bb
Add `RemoveFromSearch` meilisearch tests
stevebauman Sep 30, 2022
aba8564
Flush the container on tear down
stevebauman Sep 30, 2022
7bea1cc
Remove unneeded tearDown
stevebauman Sep 30, 2022
625ba1b
Update algolia engine to delete using custom keys
stevebauman Sep 30, 2022
745ce0b
Add Algolia deletion tests with custom keys
stevebauman Sep 30, 2022
ce381f9
Rename "$values" to "$keys" for clarity
stevebauman Sep 30, 2022
8b9270f
Spacing
stevebauman Sep 30, 2022
e137aa4
Remove unused imports
stevebauman Sep 30, 2022
d3557d2
CS fixes
stevebauman Sep 30, 2022
1934e76
Comment clarification
stevebauman Sep 30, 2022
719c096
Merge remote-tracking branch 'upstream/master' into fix-removeable-sc…
stevebauman Sep 30, 2022
a8a36c9
Remove use of `getUnqualifiedScoutKeyName()` in favour of `getScoutKe…
stevebauman Sep 30, 2022
6e32b53
Revert change of scout key extraction
stevebauman Sep 30, 2022
1ffa9fc
Revert to prefixed key to ensure Str::afterLast is used
stevebauman Sep 30, 2022
f0f3351
CS Fixes
stevebauman Sep 30, 2022
57bc89f
Merge branch 'master' into fix-removeable-scout-collection-master
stevebauman Dec 7, 2022
f351395
Update CHANGELOG.md
stevebauman Dec 7, 2022
1dc06d0
Remove `getUnqualifiedScoutKeyName()`
stevebauman Dec 7, 2022
1806b0c
Remove unused import
stevebauman Dec 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Engines/AlgoliaEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function delete($models)
$index = $this->algolia->initIndex($models->first()->searchableAs());

$keys = $models instanceof RemoveableScoutCollection
? $models->pluck($models->first()->getUnqualifiedScoutKeyName())
? $models->pluck($models->first()->getScoutKeyName())
: $models->map->getScoutKey();

$index->deleteObjects($keys->all());
Expand Down
2 changes: 1 addition & 1 deletion src/Engines/MeiliSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function delete($models)
$index = $this->meilisearch->index($models->first()->searchableAs());

$keys = $models instanceof RemoveableScoutCollection
? $models->pluck($models->first()->getUnqualifiedScoutKeyName())
? $models->pluck($models->first()->getScoutKeyName())
: $models->map->getScoutKey();

$index->deleteDocuments($keys->all());
Expand Down
11 changes: 0 additions & 11 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection as BaseCollection;
use Illuminate\Support\Str;

trait Searchable
{
Expand Down Expand Up @@ -392,16 +391,6 @@ public function getScoutKeyName()
return $this->getKeyName();
}

/**
* Get the unqualified Scout key name.
*
* @return string
*/
public function getUnqualifiedScoutKeyName()
{
return Str::afterLast($this->getScoutKeyName(), '.');
}

/**
* Determine if the current class should use soft deletes with searching.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/AlgoliaEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function test_remove_from_search_job_uses_custom_search_key()
$engine = m::mock(AlgoliaEngine::class);

$engine->shouldReceive('delete')->once()->with(m::on(function ($collection) {
$keyName = ($model = $collection->first())->getUnqualifiedScoutKeyName();
$keyName = ($model = $collection->first())->getScoutKeyName();

return $model->getAttributes()[$keyName] === 'my-algolia-key.5';
}));
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/MeiliSearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function test_remove_from_search_job_uses_custom_search_key()
$engine = m::mock(MeiliSearchEngine::class);

$engine->shouldReceive('delete')->once()->with(m::on(function ($collection) {
$keyName = ($model = $collection->first())->getUnqualifiedScoutKeyName();
$keyName = ($model = $collection->first())->getScoutKeyName();

return $model->getAttributes()[$keyName] === 'my-meilisearch-key.5';
}));
Expand Down