diff --git a/app/Console/Commands/RankingsRecalculateTopPlays.php b/app/Console/Commands/RankingsRecalculateTopPlays.php index a98f97193be..23a6d07c37b 100644 --- a/app/Console/Commands/RankingsRecalculateTopPlays.php +++ b/app/Console/Commands/RankingsRecalculateTopPlays.php @@ -9,6 +9,7 @@ use App\Libraries\Score\TopPlays; use App\Models\Beatmap; +use App\Models\Country; use Illuminate\Console\Command; class RankingsRecalculateTopPlays extends Command @@ -18,10 +19,18 @@ class RankingsRecalculateTopPlays extends Command public function handle() { + $countriesQuery = Country::where('rankedscore', '>', 0); + $countries = $countriesQuery->get(); + foreach (Beatmap::MODES as $rulesetName => $rulesetId) { $this->info("Updating top plays data for {$rulesetName}"); new TopPlays($rulesetId)->updateCache(); + + foreach ($countries as $country) { + new TopPlays($rulesetId, $country->acronym)->updateCache(); + } } + $this->info('Done'); } } diff --git a/app/Http/Controllers/Ranking/TopPlaysController.php b/app/Http/Controllers/Ranking/TopPlaysController.php index c131a847c35..4e21a0070b5 100644 --- a/app/Http/Controllers/Ranking/TopPlaysController.php +++ b/app/Http/Controllers/Ranking/TopPlaysController.php @@ -10,6 +10,7 @@ use App\Http\Controllers\Controller; use App\Libraries\Score\TopPlays; use App\Models\Beatmap; +use App\Models\CountryStatistics; use App\Models\Solo\Score; use App\Transformers\ScoreTransformer; use Symfony\Component\HttpFoundation\Response; @@ -27,7 +28,16 @@ public function show(?string $rulesetName = null): Response $rulesetId = Beatmap::MODES[$rulesetName] ?? abort(422, 'invalid ruleset parameter'); $page = \Number::clamp(get_int(\Request::input('page')) ?? 1, 1, static::PAGES); - $data = new TopPlays($rulesetId)->get(); + $country = \Request::input('country'); + + $countryStats = $country !== null + ? CountryStatistics + ::where('country_code', $country) + ->where('mode', $rulesetId) + ->firstOrFail() + : null; + + $data = new TopPlays($rulesetId, $country)->get(); if (isset($data)) { $lastUpdate = parse_time_to_carbon($data['time']); @@ -57,6 +67,7 @@ public function show(?string $rulesetName = null): Response 'rulesetName', 'scores', 'scoresJson', + 'countryStats', )); } } diff --git a/app/Libraries/Score/TopPlays.php b/app/Libraries/Score/TopPlays.php index a5b8683e5a2..fcfc2d752ea 100644 --- a/app/Libraries/Score/TopPlays.php +++ b/app/Libraries/Score/TopPlays.php @@ -16,9 +16,15 @@ class TopPlays private readonly string $key; - public function __construct(private readonly int $rulesetId) + public function __construct(private readonly int $rulesetId, private readonly ?string $countryCode = null) { - $this->key = static::KEY.':'.$this->rulesetId; + $key = static::KEY.':'.$this->rulesetId; + + if ($this->countryCode !== null) { + $key = $key.':'.$this->countryCode; + } + + $this->key = $key; } public function updateCache(): void @@ -28,6 +34,8 @@ public function updateCache(): void 'limit' => 3000, 'ruleset_id' => $this->rulesetId, 'sort' => 'pp_desc', + 'country_code' => $this->countryCode, + 'type' => $this->countryCode === null ? 'global' : 'country', ])); $search->connectionName = 'scores_slow'; $search->searchTimeout = "{$GLOBALS['cfg']['elasticsearch']['connections']['scores_slow']['connectionParams']['client']['timeout']}s"; diff --git a/resources/js/ranking-top-plays/index.tsx b/resources/js/ranking-top-plays/index.tsx index 9a73aea3f7e..6bc1ba8810c 100644 --- a/resources/js/ranking-top-plays/index.tsx +++ b/resources/js/ranking-top-plays/index.tsx @@ -18,6 +18,7 @@ import { displayMods, hasMenu } from 'utils/score-helper'; interface Props { first_score_rank: number; + mode: string; scores: ScoreJsonForTopPlays[]; } @@ -60,9 +61,9 @@ export default function RankingScores(props: Props) {
- + - + {score.user.team != null && diff --git a/resources/views/rankings/top_plays.blade.php b/resources/views/rankings/top_plays.blade.php index a11b7fec25f..623deb7d884 100644 --- a/resources/views/rankings/top_plays.blade.php +++ b/resources/views/rankings/top_plays.blade.php @@ -14,6 +14,13 @@ {{ osu_trans('rankings.top_plays.empty') }} @endsection @else + @section('ranking-header') +
+
+ @include('rankings._country_filter', ['params' => ['mode' => $rulesetName]]) +
+
+ @endsection @section('scores-header')

{{ osu_trans('rankings.top_plays.last_updated') }}: {!! timeago($lastUpdate) !!} @@ -24,6 +31,7 @@ class="u-contents js-react" data-props="{{ json_encode([ 'first_score_rank' => $scores->firstItem(), + 'mode' => $rulesetName, 'scores' => $scoresJson, ]) }}" data-react="ranking-top-plays"