Skip to content

Remove legacy score user customization impact on user score bests #11847

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use App\Libraries\RateLimiter;
use App\Libraries\Search\ForumSearch;
use App\Libraries\Search\ForumSearchRequestParams;
use App\Libraries\Search\ScoreSearchParams;
use App\Libraries\User\FindForProfilePage;
use App\Libraries\UserRegistration;
use App\Models\Beatmap;
Expand Down Expand Up @@ -179,7 +178,7 @@ public function extraPages($_id, $page)
return [
'best' => $this->getExtraSection(
'scoresBest',
count($this->user->beatmapBestScoreIds($this->mode, ScoreSearchParams::showLegacyForUser(\Auth::user())))
count($this->user->beatmapBestScoreIds($this->mode))
),
'firsts' => $this->getExtraSection(
'scoresFirsts',
Expand Down Expand Up @@ -813,8 +812,7 @@ private function getExtra($page, array $options, int $perPage = 10, int $offset
$this->mode,
$perPage,
$offset,
ScoreTransformer::USER_PROFILE_INCLUDES_PRELOAD,
ScoreSearchParams::showLegacyForUser(\Auth::user()),
ScoreTransformer::USER_PROFILE_INCLUDES_PRELOAD
);
$userRelationColumn = 'user';
break;
Expand Down
30 changes: 13 additions & 17 deletions app/Models/Traits/UserScoreable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,30 @@ trait UserScoreable
private array $beatmapBestScoreIds = [];
private array $beatmapBestScores = [];

public function aggregatedScoresBest(string $mode, null | true $legacyOnly, int $size): array
public function aggregatedScoresBest(string $mode, int $size): array
{
return (new FetchDedupedScores('beatmap_id', ScoreSearchParams::fromArray([
'exclude_without_pp' => true,
'is_legacy' => $legacyOnly,
'limit' => $size,
'ruleset_id' => Beatmap::MODES[$mode],
'sort' => 'pp_desc',
'user_id' => $this->getKey(),
]), "aggregatedScoresBest_{$mode}"))->all();
}

public function beatmapBestScoreIds(string $mode, null | true $legacyOnly)
public function beatmapBestScoreIds(string $mode)
{
$key = $mode.'-'.($legacyOnly ? '1' : '0');

if (!isset($this->beatmapBestScoreIds[$key])) {
if (!isset($this->beatmapBestScoreIds[$mode])) {
// aggregations do not support regular pagination.
// always fetching 100 to cache; we're not supporting beyond 100, either.
$this->beatmapBestScoreIds[$key] = cache_remember_mutexed(
"search-cache:beatmapBestScoresSolo:{$this->getKey()}:{$key}",
$this->beatmapBestScoreIds[$mode] = cache_remember_mutexed(
"search-cache:beatmapBestScoresSolo:{$this->getKey()}:{$mode}",
$GLOBALS['cfg']['osu']['scores']['es_cache_duration'],
[],
function () use ($key, $legacyOnly, $mode) {
$this->beatmapBestScores[$key] = $this->aggregatedScoresBest($mode, $legacyOnly, 100);
function () use ($mode) {
$this->beatmapBestScores[$mode] = $this->aggregatedScoresBest($mode, 100);

return array_column($this->beatmapBestScores[$key], 'id');
return array_column($this->beatmapBestScores[$mode], 'id');
},
function () {
// TODO: propagate a more useful message back to the client
Expand All @@ -52,16 +49,15 @@ function () {
);
}

return $this->beatmapBestScoreIds[$key];
return $this->beatmapBestScoreIds[$mode];
}

public function beatmapBestScores(string $mode, int $limit, int $offset, array $with, null | true $legacyOnly): Collection
public function beatmapBestScores(string $mode, int $limit, int $offset, array $with): Collection
{
$ids = $this->beatmapBestScoreIds($mode, $legacyOnly);
$key = $mode.'-'.($legacyOnly ? '1' : '0');
$ids = $this->beatmapBestScoreIds($mode);

if (isset($this->beatmapBestScores[$key])) {
$results = new Collection(array_slice($this->beatmapBestScores[$key], $offset, $limit));
if (isset($this->beatmapBestScores[$mode])) {
$results = new Collection(array_slice($this->beatmapBestScores[$mode], $offset, $limit));
} else {
$ids = array_slice($ids, $offset, $limit);
$results = Score::whereKey($ids)->orderByField('id', $ids)->default()->get();
Expand Down
4 changes: 1 addition & 3 deletions app/Transformers/UserCompactTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace App\Transformers;

use App\Libraries\MorphMap;
use App\Libraries\Search\ScoreSearchParams;
use App\Models\Beatmap;
use App\Models\User;
use App\Models\UserProfileCustomization;
Expand Down Expand Up @@ -412,8 +411,7 @@ public function includeReplaysWatchedCounts(User $user)
public function includeScoresBestCount(User $user)
{
return $this->primitive(count($user->beatmapBestScoreIds(
$this->mode,
ScoreSearchParams::showLegacyForUser(\Auth::user()),
$this->mode
)));
}

Expand Down
Loading