-
Notifications
You must be signed in to change notification settings - Fork 378
/
RemoveBeatmapsetSoloScores.php
69 lines (56 loc) · 1.78 KB
/
RemoveBeatmapsetSoloScores.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.
declare(strict_types=1);
namespace App\Jobs;
use App\Libraries\Search\ScoreSearch;
use App\Models\Beatmap;
use App\Models\Beatmapset;
use App\Models\Solo\Score;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;
class RemoveBeatmapsetSoloScores implements ShouldQueue
{
use Queueable;
public $timeout = 36000;
private int $beatmapsetId;
private int $maxScoreId;
private array $schemas;
private ScoreSearch $scoreSearch;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Beatmapset $beatmapset)
{
$this->beatmapsetId = $beatmapset->getKey();
$this->maxScoreId = Score::max('id') ?? 0;
}
public function displayName()
{
return static::class." (Beatmapset {$this->beatmapsetId})";
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->scoreSearch = new ScoreSearch();
$this->schemas = $this->scoreSearch->getActiveSchemas();
$beatmapIds = Beatmap::where('beatmapset_id', $this->beatmapsetId)->pluck('beatmap_id');
Score
::whereIn('beatmap_id', $beatmapIds)
->where('id', '<=', $this->maxScoreId)
->chunkById(1000, fn ($scores) => $this->deleteScores($scores));
}
private function deleteScores(Collection $scores): void
{
$ids = $scores->pluck('id')->all();
Score::whereKey($ids)->update(['ranked' => false]);
$this->scoreSearch->queueForIndex($this->schemas, $ids);
}
}