1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Console\Commands;
7
8use App\Models\BeatmapDiscussion;
9use App\Models\Beatmapset;
10use Illuminate\Console\Command;
11
12class BeatmapsetsHypeSyncCommand extends Command
13{
14 /**
15 * The console command name.
16 *
17 * @var string
18 */
19 protected $signature = 'beatmapsets:hypesync';
20
21 /**
22 * The console command description.
23 *
24 * @var string
25 */
26 protected $description = 'Synchronises hype and nomination count caches for all beatmapsets.';
27
28 private $progress;
29
30 /**
31 * Execute the console command.
32 *
33 * @return mixed
34 */
35 public function handle()
36 {
37 $this->info('Synchronising hype and nomination counts...');
38
39 $beatmapsets = Beatmapset::whereIn('beatmapset_id', BeatmapDiscussion::select('beatmapset_id')->distinct());
40 $this->progress = $this->output->createProgressBar($beatmapsets->count());
41
42 $beatmapsets->chunkById(1000, function ($sets) {
43 foreach ($sets as $set) {
44 $set->refreshCache();
45 $this->progress->advance();
46 }
47 });
48
49 $this->progress->finish();
50 }
51}