Skip to content

Commit f93aba3

Browse files
committed
disable existence check; handle null score in replay stats
1 parent d9da39a commit f93aba3

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

app/Http/Controllers/UsersController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function extraPages($_id, $page)
176176
'replays_watched_counts' => json_collection($this->user->replaysWatchedCounts, new UserReplaysWatchedCountTransformer()),
177177
'score_replay_stats' => $this->getExtraSection(
178178
'scoreReplayStats',
179-
$this->user->scoreReplayStats()->whereHas('score.beatmap')->countLimit($this->maxResults),
179+
$this->user->scoreReplayStats()->countLimit($this->maxResults),
180180
),
181181
];
182182

@@ -853,7 +853,6 @@ private function getExtra($page, array $options, int $perPage = 10, int $offset
853853
$transformer = new ScoreReplayStatsTransformer();
854854
$includes = ScoreReplayStatsTransformer::USER_PROFILE_INCLUDES;
855855
$query = $this->user->scoreReplayStats()
856-
->whereHas('score.beatmap')
857856
->orderByDesc('watch_count')
858857
->with(ScoreReplayStatsTransformer::USER_PROFILE_INCLUDES_PRELOAD);
859858
break;

app/Transformers/ScoreReplayStatsTransformer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function transform(ScoreReplayStats $stats): array
3030

3131
public function includeScore(ScoreReplayStats $stats): ResourceInterface
3232
{
33-
return $this->item($stats->score, new ScoreTransformer());
33+
return $stats->score !== null
34+
? $this->item($stats->score, new ScoreTransformer())
35+
: $this->null();
3436
}
3537
}

resources/js/interfaces/score-replay-stats-json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ScoreJson, { ScoreJsonForUser } from './score-json';
55

66
interface ScoreReplayStatsJsonAvailableIncludes {
7-
score: ScoreJson;
7+
score: ScoreJson|null;
88
}
99

1010
interface ScoreReplayStatsJsonDefaultAttributes {
@@ -16,4 +16,4 @@ type ScoreReplayStatsJson = ScoreReplayStatsJsonDefaultAttributes & Partial<Scor
1616

1717
export default ScoreReplayStatsJson;
1818

19-
export type ScoreReplayStatsJsonForUser = ScoreReplayStatsJson & { score: ScoreJsonForUser };
19+
export type ScoreReplayStatsJsonForUser = ScoreReplayStatsJson & { score: ScoreJsonForUser|null };

resources/js/profile-page/score-replay-stats-entry.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export default function ScoreReplayStatsEntry(props: Props) {
2525
const user = props.user;
2626
const stats = props.stats;
2727
const score = stats.score;
28+
if (score == null) {
29+
return null;
30+
}
31+
2832
const scoreRank = rank(score);
2933
const { beatmap, beatmapset } = score;
3034

0 commit comments

Comments
 (0)