Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions app/Console/Commands/RankingsRecalculateTopPlays.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
13 changes: 12 additions & 1 deletion app/Http/Controllers/Ranking/TopPlaysController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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']);
Expand Down Expand Up @@ -57,6 +67,7 @@ public function show(?string $rulesetName = null): Response
'rulesetName',
'scores',
'scoresJson',
'countryStats',
));
}
}
12 changes: 10 additions & 2 deletions app/Libraries/Score/TopPlays.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
5 changes: 3 additions & 2 deletions resources/js/ranking-top-plays/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { displayMods, hasMenu } from 'utils/score-helper';

interface Props {
first_score_rank: number;
mode: string;
scores: ScoreJsonForTopPlays[];
}

Expand Down Expand Up @@ -60,9 +61,9 @@ export default function RankingScores(props: Props) {
<div className='ranking-page-grid-item__col ranking-page-grid-item__col--main'>
<div className='ranking-page-table-main'>
<span className='ranking-page-table-main__flag'>
<span className='u-contents u-hover'>
<a className='u-contents u-hover' href={route('rankings.top-plays', { country: score.user.country_code, mode: props.mode })}>
<FlagCountry country={score.user.country} />
</span>
</a>
</span>
{score.user.team != null &&
<span className='ranking-page-table-main__flag'>
Expand Down
8 changes: 8 additions & 0 deletions resources/views/rankings/top_plays.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
{{ osu_trans('rankings.top_plays.empty') }}
@endsection
@else
@section('ranking-header')
<div class="osu-page osu-page--ranking-info">
<div class="grid-items grid-items--ranking-filter">
@include('rankings._country_filter', ['params' => ['mode' => $rulesetName]])
</div>
</div>
@endsection
@section('scores-header')
<p>
<small>{{ osu_trans('rankings.top_plays.last_updated') }}: {!! timeago($lastUpdate) !!}</small>
Expand All @@ -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"
Expand Down