Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update score table structure #10869

Merged
merged 16 commits into from
Jan 24, 2024
2 changes: 1 addition & 1 deletion app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function soloScores($id)
'type' => $type,
'user' => $currentUser,
]);
$scores = $esFetch->all()->loadMissing(['beatmap', 'performance', 'user.country', 'user.userProfileCustomization']);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'user.userProfileCustomization']);
$userScore = $esFetch->userBest();
$scoreTransformer = new ScoreTransformer(ScoreTransformer::TYPE_SOLO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,13 @@ public function update($roomId, $playlistItemId, $tokenId)
});

$score = $scoreLink->score;
$transformer = ScoreTransformer::newSolo();
if ($score->wasRecentlyCreated) {
$scoreJson = json_item($score, $transformer);
$score::queueForProcessing($scoreJson);
$score->queueForProcessing();
}

return json_item(
$scoreLink,
$transformer,
ScoreTransformer::newSolo(),
[
...ScoreTransformer::MULTIPLAYER_BASE_INCLUDES,
'position',
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/Solo/ScoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public function store($beatmapId, $tokenId)
return $score;
});

$scoreJson = json_item($score, new ScoreTransformer(ScoreTransformer::TYPE_SOLO));
if ($score->wasRecentlyCreated) {
$score::queueForProcessing($scoreJson);
$score->queueForProcessing();
}

return $scoreJson;
return json_item($score, new ScoreTransformer(ScoreTransformer::TYPE_SOLO));
}
}
2 changes: 0 additions & 2 deletions app/Jobs/RemoveBeatmapsetSoloScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Models\Beatmap;
use App\Models\Beatmapset;
use App\Models\Solo\Score;
use App\Models\Solo\ScorePerformance;
use DB;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -68,7 +67,6 @@ private function deleteScores(Collection $scores): void
$scoresQuery->update(['preserve' => false]);
$this->scoreSearch->queueForIndex($this->schemas, $ids);
DB::transaction(function () use ($ids, $scoresQuery): void {
ScorePerformance::whereKey($ids)->delete();
$scoresQuery->delete();
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/Libraries/Search/ScoreSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function getQuery(): BoolQuery
$beforeTotalScore = $this->params->beforeTotalScore;
if ($beforeTotalScore === null && $this->params->beforeScore !== null) {
$beforeTotalScore = $this->params->beforeScore->isLegacy()
? $this->params->beforeScore->data->legacyTotalScore
: $this->params->beforeScore->data->totalScore;
? $this->params->beforeScore->legacy_total_score
: $this->params->beforeScore->total_score;
}
if ($beforeTotalScore !== null) {
$scoreQuery = (new BoolQuery())->shouldMatch(1);
Expand Down
6 changes: 3 additions & 3 deletions app/Models/Multiplayer/PlaylistItemUserHighScore.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function scoresAround(ScoreLink $scoreLink): array
{
$placeholder = new static([
'score_id' => $scoreLink->getKey(),
'total_score' => $scoreLink->score->data->totalScore,
'total_score' => $scoreLink->score->total_score,
]);

static $typeOptions = [
Expand Down Expand Up @@ -117,10 +117,10 @@ public function updateWithScoreLink(ScoreLink $scoreLink): void
$score = $scoreLink->score;

$this->fill([
'accuracy' => $score->data->accuracy,
'accuracy' => $score->accuracy,
'pp' => $score->pp,
'score_id' => $scoreLink->getKey(),
'total_score' => $score->data->totalScore,
'total_score' => $score->total_score,
])->save();
}
}
2 changes: 1 addition & 1 deletion app/Models/Multiplayer/ScoreLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function position(): ?int
$query = PlaylistItemUserHighScore
::where('playlist_item_id', $this->playlist_item_id)
->cursorSort('score_asc', [
'total_score' => $score->data->totalScore,
'total_score' => $score->total_score,
'score_id' => $this->getKey(),
]);

Expand Down
8 changes: 4 additions & 4 deletions app/Models/Multiplayer/UserScoreAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function addScoreLink(ScoreLink $scoreLink, ?PlaylistItemUserHighScore $h
$scoreLink->playlist_item_id,
);

if ($score->data->passed && $score->data->totalScore > $highestScore->total_score) {
if ($score->passed && $score->total_score > $highestScore->total_score) {
$this->updateUserTotal($scoreLink, $highestScore);
$highestScore->updateWithScoreLink($scoreLink);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public function recalculate()
$scoreLinks = ScoreLink
::whereHas('playlistItem', fn ($q) => $q->where('room_id', $this->room_id))
->where('user_id', $this->user_id)
->with('score.performance')
->with('score')
->get();
foreach ($scoreLinks as $scoreLink) {
$this->addScoreLink(
Expand Down Expand Up @@ -221,8 +221,8 @@ private function updateUserTotal(ScoreLink $currentScoreLink, PlaylistItemUserHi

$current = $currentScoreLink->score;

$this->total_score += $current->data->totalScore;
$this->accuracy += $current->data->accuracy;
$this->total_score += $current->total_score;
$this->accuracy += $current->accuracy;
$this->pp += $current->pp;
$this->completed++;
$this->last_score_id = $currentScoreLink->getKey();
Expand Down
6 changes: 5 additions & 1 deletion app/Models/Score/Best/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ public function getAttribute($key)
'date_json' => $this->getJsonTimeFast($key),

'best' => $this,
'data' => $this->getData(),
'enabled_mods' => $this->getEnabledModsAttribute($this->getRawAttribute('enabled_mods')),
'pass' => true,

'best_id' => $this->getKey(),
'has_replay' => $this->replay,

'beatmap',
'replayViewCount',
'reportedIn',
'user' => $this->getRelationValue($key),

default => $this->getNewScoreAttribute($key),
};
}

Expand Down
53 changes: 33 additions & 20 deletions app/Models/Score/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Models\Score;

use App\Enums\Ruleset;
use App\Exceptions\ClassNotFoundException;
use App\Libraries\Mods;
use App\Models\Beatmap;
Expand Down Expand Up @@ -146,13 +147,36 @@ public function getAttribute($key)

'date_json' => $this->getJsonTimeFast($key),

'data' => $this->getData(),
'enabled_mods' => $this->getEnabledModsAttribute($this->getRawAttribute('enabled_mods')),

'best_id' => $this->getRawAttribute('high_score_id'),
'has_replay' => $this->best?->replay,
'pp' => $this->best?->pp,

'beatmap',
'best',
'replayViewCount',
'user' => $this->getRelationValue($key),

default => $this->getNewScoreAttribute($key),
};
}

public function getNewScoreAttribute(string $key)
{
return match ($key) {
'accuracy' => $this->accuracy(),
'build_id' => null,
'data' => $this->getData(),
'ended_at_json' => $this->date_json,
'legacy_perfect' => $this->perfect,
'legacy_score_id' => $this->getKey(),
'legacy_total_score' => $this->score,
'max_combo' => $this->maxcombo,
'passed' => $this->pass,
'ruleset_id' => Ruleset::tryFromName($this->getMode())->value,
'started_at_json' => null,
'total_score' => $this->score,
};
}

Expand All @@ -161,47 +185,36 @@ public function getMode(): string
return snake_case(get_class_basename(static::class));
}

protected function getData()
public function getData(): ScoreData
{
$mods = array_map(fn ($m) => ['acronym' => $m, 'settings' => []], $this->enabled_mods);

$statistics = [
'miss' => $this->countmiss,
'great' => $this->count300,
];
$ruleset = $this->getMode();
$ruleset = Ruleset::tryFromName($this->getMode());
switch ($ruleset) {
case 'osu':
case Ruleset::osu:
$statistics['ok'] = $this->count100;
$statistics['meh'] = $this->count50;
break;
case 'taiko':
case Ruleset::taiko:
$statistics['ok'] = $this->count100;
break;
case 'fruits':
case Ruleset::catch:
$statistics['large_tick_hit'] = $this->count100;
$statistics['small_tick_hit'] = $this->count50;
$statistics['small_tick_miss'] = $this->countkatu;
break;
case 'mania':
case Ruleset::mania:
$statistics['perfect'] = $this->countgeki;
$statistics['good'] = $this->countkatu;
$statistics['ok'] = $this->count100;
$statistics['meh'] = $this->count50;
break;
}

return new ScoreData([
'accuracy' => $this->accuracy(),
'beatmap_id' => $this->beatmap_id,
'ended_at' => $this->date_json,
'max_combo' => $this->maxcombo,
'mods' => $mods,
'passed' => $this->pass,
'rank' => $this->rank,
'ruleset_id' => Beatmap::modeInt($ruleset),
'statistics' => $statistics,
'total_score' => $this->score,
'user_id' => $this->user_id,
]);
return new ScoreData(compact('mods', 'statistics'));
}
}
Loading
Loading