mirror of
https://github.com/koel/koel
synced 2024-11-28 06:50:27 +00:00
fix: conflict during merge
This commit is contained in:
commit
e25d22b41c
2 changed files with 9 additions and 5 deletions
|
@ -17,9 +17,11 @@ trait SupportsDeleteWhereValueNotIn
|
|||
/**
|
||||
* Deletes all records whose certain value is not in an array.
|
||||
*/
|
||||
public static function deleteWhereValueNotIn(array $values, string $field = 'id'): void
|
||||
public static function deleteWhereValueNotIn(array $values, ?string $field = null): void
|
||||
{
|
||||
$maxChunkSize = DB::getDriverName() === 'sqlite' ? 999 : 65535;
|
||||
$field ??= (new static())->getKeyName();
|
||||
|
||||
$maxChunkSize = DB::getDriverName() === 'sqlite' ? 999 : 65_535;
|
||||
|
||||
if (count($values) <= $maxChunkSize) {
|
||||
static::query()->whereNotIn($field, $values)->delete();
|
||||
|
@ -36,11 +38,13 @@ trait SupportsDeleteWhereValueNotIn
|
|||
return;
|
||||
}
|
||||
|
||||
static::deleteByChunk($deletableIds, $field, $maxChunkSize);
|
||||
static::deleteByChunk($deletableIds, $maxChunkSize, $field);
|
||||
}
|
||||
|
||||
public static function deleteByChunk(array $values, string $field = 'id', int $chunkSize = 65535): void
|
||||
public static function deleteByChunk(array $values, int $chunkSize = 65_535, ?string $field = null): void
|
||||
{
|
||||
$field ??= (new static())->getKeyName();
|
||||
|
||||
DB::transaction(static function () use ($values, $field, $chunkSize): void {
|
||||
foreach (array_chunk($values, $chunkSize) as $chunk) {
|
||||
static::query()->whereIn($field, $chunk)->delete();
|
||||
|
|
|
@ -323,7 +323,7 @@ class SongTest extends TestCase
|
|||
self::assertNotSame(0, Song::query()->count());
|
||||
$ids = Song::query()->select('id')->get()->pluck('id')->all();
|
||||
|
||||
Song::deleteByChunk($ids, 'id', 1);
|
||||
Song::deleteByChunk($ids, 1);
|
||||
|
||||
self::assertSame(0, Song::query()->count());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue