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

Use solo scores for profile page recent plays #9438

Merged
merged 2 commits into from
Jan 24, 2024
Merged
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
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
9 changes: 6 additions & 3 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function extraPages($_id, $page)
'monthly_playcounts' => json_collection($this->user->monthlyPlaycounts, new UserMonthlyPlaycountTransformer()),
'recent' => $this->getExtraSection(
'scoresRecent',
$this->user->scores($this->mode, true)->includeFails(false)->count()
$this->user->recentScoreCount($this->mode)
),
'replays_watched_counts' => json_collection($this->user->replaysWatchedCounts, new UserReplaysWatchedCountTransformer()),
];
Expand Down Expand Up @@ -814,9 +814,12 @@ private function getExtra($page, array $options, int $perPage = 10, int $offset
case 'scoresRecent':
$transformer = new ScoreTransformer();
$includes = ScoreTransformer::USER_PROFILE_INCLUDES;
$query = $this->user->scores($this->mode, true)
$query = $this->user->soloScores()
->default()
->forRuleset($this->mode)
->includeFails($options['includeFails'] ?? false)
->with([...ScoreTransformer::USER_PROFILE_INCLUDES_PRELOAD, 'best']);
->reorderBy('id', 'desc')
->with(ScoreTransformer::USER_PROFILE_INCLUDES_PRELOAD);
$userRelationColumn = 'user';
break;
}
Expand Down
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
29 changes: 8 additions & 21 deletions app/Models/Score/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace App\Models\Score;

use App\Enums\Ruleset;
use App\Exceptions\ClassNotFoundException;
use App\Libraries\Mods;
use App\Models\Beatmap;
use App\Models\Model as BaseModel;
use App\Models\Solo\ScoreData;
use App\Models\Traits\Scoreable;
use App\Models\User;

Expand Down Expand Up @@ -161,47 +161,34 @@ public function getMode(): string
return snake_case(get_class_basename(static::class));
}

protected function getData()
public function statistics(): array
{
$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 $statistics;
}
}
Loading