Skip to content

Commit d8b38f8

Browse files
authored
Merge branch 'master' into feature/beatmapset-show-user-tags-search
2 parents 390d752 + 52422e0 commit d8b38f8

22 files changed

+804
-898
lines changed

app/Http/Controllers/BeatmapsController.php

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private static function beatmapScores(string $id, ?string $scoreTransformerType,
7979
$scoreTransformer = new ScoreTransformer($scoreTransformerType);
8080

8181
$results = [
82+
'score_count' => UserRank::getCount($esFetch->baseParams),
8283
'scores' => json_collection(
8384
$scores,
8485
$scoreTransformer,

app/Http/Controllers/BeatmapsetsController.php

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function show($id)
112112
}
113113

114114
/**
115+
* Search Beatmapset
116+
*
115117
* TODO: documentation
116118
*
117119
* @usesCursor

app/Libraries/Score/BeatmapScores.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
class BeatmapScores
1616
{
17+
public ScoreSearchParams $baseParams;
1718
public array $result;
18-
private ScoreSearchParams $baseParams;
1919

2020
public function __construct(private array $rawParams)
2121
{
@@ -48,7 +48,6 @@ public function rank(SoloScore $score): int
4848

4949
$params = clone $this->baseParams;
5050
$params->beforeScore = $score;
51-
$params->setSort(null);
5251

5352
return UserRank::getRank($params);
5453
}

app/Libraries/Score/UserRank.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111

1212
class UserRank
1313
{
14-
public static function getRank(ScoreSearchParams $params): int
14+
public static function getCount(ScoreSearchParams $params): int
1515
{
16-
if ($params->beforeTotalScore === null && $params->beforeScore === null) {
17-
throw new InvariantException('beforeScore or beforeTotalScore must be specified');
18-
}
19-
16+
$params->setSort(null);
2017
$search = new ScoreSearch($params);
2118

2219
$search->size(0);
@@ -27,6 +24,15 @@ public static function getRank(ScoreSearchParams $params): int
2724
$response = $search->response();
2825
$search->assertNoError();
2926

30-
return 1 + $response->aggregations($aggName)['value'];
27+
return $response->aggregations($aggName)['value'];
28+
}
29+
30+
public static function getRank(ScoreSearchParams $params): int
31+
{
32+
if ($params->beforeTotalScore === null && $params->beforeScore === null) {
33+
throw new InvariantException('beforeScore or beforeTotalScore must be specified');
34+
}
35+
36+
return 1 + static::getCount($params);
3137
}
3238
}

app/Models/Beatmap.php

+12-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use App\Jobs\EsDocumentUnique;
1010
use App\Libraries\Transactions\AfterCommit;
1111
use App\Traits\Memoizes;
12-
use DB;
1312
use Illuminate\Database\Eloquent\Builder;
1413
use Illuminate\Database\Eloquent\Collection;
1514
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -166,21 +165,18 @@ public function scopeScoreable($query)
166165

167166
public function scopeWithMaxCombo($query)
168167
{
169-
$mods = BeatmapDifficultyAttrib::NO_MODS;
170-
$attrib = BeatmapDifficultyAttrib::MAX_COMBO;
171-
$attribTable = (new BeatmapDifficultyAttrib())->tableName();
172-
$mode = $this->qualifyColumn('playmode');
173-
$id = $this->qualifyColumn('beatmap_id');
174-
175-
return $query
176-
->addSelect(['attrib_max_combo' => DB::raw("(
177-
SELECT value
178-
FROM {$attribTable}
179-
WHERE beatmap_id = {$id}
180-
AND mode = {$mode}
181-
AND mods = {$mods}
182-
AND attrib_id = {$attrib}
183-
)")]);
168+
$valueQuery = BeatmapDifficultyAttrib
169+
::select('value')
170+
->whereColumn([
171+
'beatmap_id' => $this->qualifyColumn('beatmap_id'),
172+
'mode' => $this->qualifyColumn('playmode'),
173+
])
174+
->where([
175+
'attrib_id' => BeatmapDifficultyAttrib::MAX_COMBO,
176+
'mods' => BeatmapDifficultyAttrib::NO_MODS,
177+
]);
178+
179+
return $query->addSelect(['attrib_max_combo' => $valueQuery]);
184180
}
185181

186182
public function scopeWithUserPlaycount(Builder $query, ?int $userId): Builder

app/Models/Multiplayer/PlaylistItemUserHighScore.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ public function updateWithScoreLink(ScoreLink $scoreLink): bool
127127
{
128128
$score = $scoreLink->score;
129129

130-
if ($score === null || !$score->passed || $score->total_score <= $this->total_score) {
130+
if ($score === null || $score->total_score <= $this->total_score) {
131+
return false;
132+
}
133+
134+
if (!$score->passed && !$scoreLink->playlistItem->room->isRealtime()) {
131135
return false;
132136
}
133137

app/Models/Multiplayer/Room.php

+4
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ public function completePlay(ScoreToken $scoreToken, array $params): ScoreLink
460460
$this->assertValidCompletePlay();
461461

462462
return $this->getConnection()->transaction(function () use ($params, $scoreToken) {
463+
$playlistItem = $scoreToken->playlistItem()->firstOrFail();
464+
$playlistItem->setRelation('room', $this);
465+
$scoreToken->setRelation('playlistItem', $playlistItem);
466+
463467
$scoreLink = ScoreLink::complete($scoreToken, $params);
464468
$user = $scoreLink->user;
465469
$agg = UserScoreAggregate::new($user, $this);

app/Models/Multiplayer/ScoreLink.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static function complete(ScoreToken $token, array $params): static
3131
// multiplayer scores are always preserved.
3232
$score = Score::createFromJsonOrExplode([...$params, 'preserve' => true]);
3333

34-
$playlistItem = $token->playlistItem()->firstOrFail();
34+
$playlistItem = $token->playlistItem;
3535
$requiredMods = array_column($playlistItem->required_mods, 'acronym');
3636
$mods = array_column($score->data->mods, 'acronym');
3737
$mods = app('mods')->excludeModsAlwaysValidForSubmission($score->ruleset_id, $mods);

app/Models/Multiplayer/UserScoreAggregate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function recalculate()
121121
$scoreLinks = ScoreLink
122122
::whereHas('playlistItem', fn ($q) => $q->where('room_id', $this->room_id))
123123
->where('user_id', $this->user_id)
124-
->with('score')
124+
->with(['score', 'playlistItem.room'])
125125
->get();
126126
foreach ($scoreLinks as $scoreLink) {
127127
($playlistItemAggs[$scoreLink->playlist_item_id]

app/Models/ScoreToken.php

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @property int|null $build_id
1818
* @property \Carbon\Carbon|null $created_at
1919
* @property int $id
20+
* @property \App\Models\Multiplayer\PlaylistItem $playlistItem
2021
* @property int $ruleset_id
2122
* @property \App\Models\Solo\Score $score
2223
* @property int $score_id

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"guzzlehttp/guzzle": "*",
2727
"itsgoingd/clockwork": "^5.1",
2828
"jenssegers/agent": "*",
29-
"knuckleswtf/scribe": "^4.0",
29+
"knuckleswtf/scribe": "^5.1",
3030
"laravel/framework": "^10.15.0",
3131
"laravel/helpers": "*",
3232
"laravel/octane": "*",
@@ -52,11 +52,11 @@
5252
"require-dev": {
5353
"beyondcode/laravel-query-detector": "*",
5454
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
55-
"dms/phpunit-arraysubset-asserts": "^0.3.0",
55+
"dms/phpunit-arraysubset-asserts": "^0.5.0",
5656
"laravel/dusk": "*",
5757
"mockery/mockery": "*",
5858
"nunomaduro/collision": "^6.1",
59-
"phpunit/phpunit": ">=9.5",
59+
"phpunit/phpunit": ">=10.0",
6060
"slevomat/coding-standard": "^8.15",
6161
"spatie/laravel-ignition": "^2.0",
6262
"squizlabs/php_codesniffer": "^3.10",

0 commit comments

Comments
 (0)