Skip to content

Commit

Permalink
Merge branch 'master' into queue-datadog-log-command-name
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Apr 24, 2024
2 parents 7f5b514 + ab6120f commit e1fbd38
Show file tree
Hide file tree
Showing 29 changed files with 267 additions and 188 deletions.
16 changes: 15 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Handler extends ExceptionHandler
public static function exceptionMessage($e)
{
if ($e instanceof ModelNotFoundException) {
return;
return static::modelNotFoundMessage($e);
}

if (static::statusCode($e) >= 500) {
Expand Down Expand Up @@ -90,6 +90,20 @@ private static function isOAuthSessionException(Throwable $e): bool
&& $e->getMessage() === 'Authorization request was not present in the session.';
}

private static function modelNotFoundMessage(ModelNotFoundException $e): string
{
$model = $e->getModel();
$modelTransKey = "models.name.{$model}";

$params = [
'model' => trans_exists($modelTransKey, $GLOBALS['cfg']['app']['fallback_locale'])
? osu_trans($modelTransKey)
: trim(strtr($model, ['App\Models\\' => '']), '\\'),
];

return osu_trans('models.not_found', $params);
}

private static function reportWithSentry(Throwable $e): void
{
$ref = log_error_sentry($e, ['http_code' => (string) static::statusCode($e)]);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static function beatmapScores(string $id, ?string $scoreTransformerType,
'type' => $type,
'user' => $currentUser,
]);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country']);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'processHistory']);
$userScore = $esFetch->userBest();
$scoreTransformer = new ScoreTransformer($scoreTransformerType);

Expand Down Expand Up @@ -494,7 +494,7 @@ public function userScoreAll($beatmapId, $userId)
'sort' => 'score_desc',
'user_id' => (int) $userId,
]);
$scores = (new ScoreSearch($params))->records();
$scores = (new ScoreSearch($params))->records()->loadMissing('processHistory');

return [
'scores' => json_collection($scores, new ScoreTransformer()),
Expand Down
16 changes: 13 additions & 3 deletions app/Http/Controllers/ScoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ public function download($rulesetOrSoloId, $id = null)

public function show($rulesetOrSoloId, $legacyId = null)
{
$scoreQuery = $legacyId === null
? SoloScore::whereKey($rulesetOrSoloId)
: SoloScore::where([
if ($legacyId === null) {
$scoreQuery = SoloScore::whereKey($rulesetOrSoloId);
} else {
// `SoloScore` tables can have records with `legacy_score_id = 0`
// which correspond to rows from `osu_scores_*` (non-high) tables.
// do not attempt to perform lookups for zero to avoid weird results.
// negative IDs should never occur (ID columns in score tables are all `bigint unsigned`).
if ($legacyId <= 0) {
abort(404, 'invalid score ID');
}

$scoreQuery = SoloScore::where([
'ruleset_id' => Ruleset::tryFromName($rulesetOrSoloId) ?? abort(404, 'unknown ruleset name'),
'legacy_score_id' => $legacyId,
]);
}
$score = $scoreQuery->whereHas('beatmap.beatmapset')->visibleUsers()->firstOrFail();

$userIncludes = array_map(function ($include) {
Expand Down
2 changes: 2 additions & 0 deletions app/Libraries/Search/ArtistTrackSearchParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class ArtistTrackSearchParams extends SearchParams
public ?string $album;
public ?string $artist;
public ?array $bpm;
public ?array $bpmInput;
public bool $exclusiveOnly = false;
public ?string $genre;
public bool $isDefaultSort = false;
public ?array $length;
public ?array $lengthInput;
public string $sortField;
public string $sortOrder;

Expand Down
8 changes: 1 addition & 7 deletions app/Models/Chat/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,8 @@ public function receiveMessage(User $sender, ?string $content, bool $isAction =
throw new API\ExcessiveChatMessagesException(osu_trans('api.error.chat.limit_exceeded'));
}

$chatFilters = app('chat-filters')->all();

foreach ($chatFilters as $filter) {
$content = str_replace($filter->match, $filter->replacement, $content);
}

$message = new Message([
'content' => $content,
'content' => app('chat-filters')->filter($content),
'is_action' => $isAction,
'timestamp' => $now,
]);
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Solo/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public function user()
return $this->belongsTo(User::class, 'user_id');
}

public function processHistory()
{
return $this->hasOne(ScoreProcessHistory::class, 'score_id');
}

public function scopeDefault(Builder $query): Builder
{
return $query->whereHas('beatmap.beatmapset');
Expand Down Expand Up @@ -243,6 +248,7 @@ public function getAttribute($key)

'beatmap',
'performance',
'processHistory',
'reportedIn',
'user' => $this->getRelationValue($key),
};
Expand Down
25 changes: 25 additions & 0 deletions app/Models/Solo/ScoreProcessHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Models\Solo;

use App\Models\Model;

/**
* @property int $score_id
* @property int $processed_version
* @property \Carbon\Carbon $processed_at
*/
class ScoreProcessHistory extends Model
{
protected $table = 'score_process_history';

public function score()
{
return $this->belongsTo(Score::class, 'score_id');
}
}
17 changes: 10 additions & 7 deletions app/Singletons/ChatFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@

use App\Models\ChatFilter;
use App\Traits\Memoizes;
use Illuminate\Database\Eloquent\Collection;

class ChatFilters
{
use Memoizes;

public function all()
public function filter(string $text): string
{
return $this->memoize(__FUNCTION__, fn () => $this->fetch());
}
$replacements = $this->memoize(__FUNCTION__, function () {
$ret = [];
foreach (ChatFilter::all() as $entry) {
$ret[$entry->match] = $entry->replacement;
}

protected function fetch(): Collection
{
return ChatFilter::all();
return $ret;
});

return strtr($text, $replacements);
}
}
9 changes: 0 additions & 9 deletions app/Transformers/Multiplayer/RoomTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class RoomTransformer extends TransformerAbstract
'playlist',
'playlist_item_stats',
'recent_participants',
'scores',
];

public function transform(Room $room)
Expand Down Expand Up @@ -94,12 +93,4 @@ public function includePlaylistItemStats(Room $room)
{
return $this->primitive($room->playlistItemStats());
}

public function includeScores(Room $room)
{
return $this->collection(
$room->scores()->completed()->get(),
new ScoreTransformer()
);
}
}
3 changes: 3 additions & 0 deletions app/Transformers/ScoreTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ScoreTransformer extends TransformerAbstract
// warning: the preload is actually for PlaylistItemUserHighScore, not for Score
const MULTIPLAYER_BASE_PRELOAD = [
'scoreLink.score',
'scoreLink.score.processHistory',
'scoreLink.user.country',
];

Expand All @@ -35,6 +36,7 @@ class ScoreTransformer extends TransformerAbstract
const USER_PROFILE_INCLUDES_PRELOAD = [
'beatmap',
'beatmap.beatmapset',
'processHistory',
// it's for user profile so the user is already available
// 'user',
];
Expand Down Expand Up @@ -102,6 +104,7 @@ public function transformSolo(MultiplayerScoreLink|ScoreModel|SoloScore $score)
if ($score instanceof SoloScore) {
$extraAttributes['ranked'] = $score->ranked;
$extraAttributes['preserve'] = $score->preserve;
$extraAttributes['processed'] = $score->legacy_score_id !== null || $score->processHistory !== null;
}

$hasReplay = $score->has_replay;
Expand Down
1 change: 0 additions & 1 deletion resources/js/components/block-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default class BlockButton extends React.Component<Props> {
if (core.currentUser != null) {
core.currentUser.blocks = data.filter((d) => d.relation_type === 'block');
core.currentUser.friends = data.filter((d) => d.relation_type === 'friend');
$.publish('user:update', core.currentUser);
}

this.props.onClick?.();
Expand Down
8 changes: 3 additions & 5 deletions resources/js/components/follow-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface State {
toggling: boolean;
}

// TODO: mobx and turn to observer
export default class FollowToggle extends React.PureComponent<Props, State> {
static defaultProps = {
following: true,
Expand Down Expand Up @@ -81,10 +82,7 @@ export default class FollowToggle extends React.PureComponent<Props, State> {
this.toggleXhr = $.ajax(route('follows.store'), { data: params, method })
.done(() => {
if (this.props.follow.subtype === 'mapping') {
$.publish('user:followUserMapping:update', {
following: !this.state.following,
userId: this.props.follow.notifiable_id,
});
core.currentUserModel.updateFollowUserMapping(!this.state.following, this.props.follow.notifiable_id);
} else {
this.setState({ following: !this.state.following });
}
Expand All @@ -97,7 +95,7 @@ export default class FollowToggle extends React.PureComponent<Props, State> {
private readonly refresh = () => {
if (this.props.follow.subtype === 'mapping') {
this.setState({
following: core.currentUser != null && core.currentUser.follow_user_mapping.includes(this.props.follow.notifiable_id),
following: core.currentUserModel.following.has(this.props.follow.notifiable_id),
});
}
};
Expand Down
7 changes: 4 additions & 3 deletions resources/js/components/follow-user-mapping-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface State {

const bn = 'user-action-button';

// TODO: mobx and turn to observer
export default class FollowUserMappingButton extends React.Component<Props, State> {
private readonly buttonRef = React.createRef<HTMLButtonElement>();
private readonly eventId = `follow-user-mapping-button-${nextVal()}`;
Expand All @@ -35,7 +36,7 @@ export default class FollowUserMappingButton extends React.Component<Props, Stat
constructor(props: Props) {
super(props);

const following = core.currentUser?.follow_user_mapping.includes(this.props.userId) ?? false;
const following = core.currentUserModel.following.has(this.props.userId);
let followersWithoutSelf = this.props.followers ?? 0;

if (following !== false) followersWithoutSelf -= 1;
Expand Down Expand Up @@ -123,7 +124,7 @@ export default class FollowUserMappingButton extends React.Component<Props, Stat

private readonly refresh = () => {
this.setState({
following: core.currentUser?.follow_user_mapping.includes(this.props.userId) ?? false,
following: core.currentUserModel.following.has(this.props.userId),
});
};

Expand Down Expand Up @@ -152,6 +153,6 @@ export default class FollowUserMappingButton extends React.Component<Props, Stat
}

private readonly updateData = () => {
$.publish('user:followUserMapping:update', { following: !this.state.following, userId: this.props.userId });
core.currentUserModel.updateFollowUserMapping(!this.state.following, this.props.userId);
};
}
1 change: 0 additions & 1 deletion resources/js/components/friend-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export default class FriendButton extends React.Component<Props> {

// TODO: move logic to a user object?
core.currentUser.friends = data;
$.publish('user:update', core.currentUser);
dispatch(new FriendUpdated(this.props.userId));
};
}
32 changes: 0 additions & 32 deletions resources/js/core-legacy/account-edit-blocklist.coffee

This file was deleted.

55 changes: 0 additions & 55 deletions resources/js/core-legacy/current-user-observer.coffee

This file was deleted.

0 comments on commit e1fbd38

Please sign in to comment.