From 5ba9fe354b57c577da1b3b79e6d8d51ef1f0f8f7 Mon Sep 17 00:00:00 2001 From: nanaya Date: Thu, 10 Oct 2024 21:04:52 +0900 Subject: [PATCH] Remove usage of old score es index --- .env.example | 1 - .../Commands/UserBestScoresCheckCommand.php | 30 ----- .../Controllers/LegacyInterOpController.php | 12 -- app/Jobs/RemoveBeatmapsetBestScores.php | 8 -- app/Libraries/UserBestScoresCheck.php | 116 ------------------ config/elasticsearch.php | 3 - docker-compose.yml | 1 - routes/web.php | 1 - 8 files changed, 172 deletions(-) delete mode 100644 app/Console/Commands/UserBestScoresCheckCommand.php delete mode 100644 app/Libraries/UserBestScoresCheck.php diff --git a/.env.example b/.env.example index 7c5b8beb274..38932f88b36 100644 --- a/.env.example +++ b/.env.example @@ -183,7 +183,6 @@ CLIENT_CHECK_VERSION=false # BAN_PERSIST_DAYS=28 # ES_HOST=localhost:9200 -# ES_SCORES_HOST=localhost:9200 # ES_SOLO_SCORES_HOST=localhost:9200 # ES_INDEX_PREFIX= # ES_CLIENT_TIMEOUT=5 diff --git a/app/Console/Commands/UserBestScoresCheckCommand.php b/app/Console/Commands/UserBestScoresCheckCommand.php deleted file mode 100644 index 0b62c7cdc3e..00000000000 --- a/app/Console/Commands/UserBestScoresCheckCommand.php +++ /dev/null @@ -1,30 +0,0 @@ -. Licensed under the GNU Affero General Public License v3.0. -// See the LICENCE file in the repository root for full licence text. - -namespace App\Console\Commands; - -use App\Libraries\UserBestScoresCheck; -use App\Models\User; -use Illuminate\Console\Command; - -class UserBestScoresCheckCommand extends Command -{ - protected $signature = 'user:check-best-scores {userId} {mode}'; - - protected $description = 'Removes the best scores for a given user from elasticsearch if it no longer exists in the database.'; - - public function handle() - { - $mode = $this->argument('mode'); - $user = User::findOrFail($this->argument('userId')); - - $checker = new UserBestScoresCheck($user); - $response = $checker->run($mode); - - $this->line("Found {$checker->esIdsFound} in index, {$checker->dbIdsFound} valid."); - $this->line('Delete query response from elasticsearch:'); - $this->line(json_encode($response, JSON_PRETTY_PRINT)); - } -} diff --git a/app/Http/Controllers/LegacyInterOpController.php b/app/Http/Controllers/LegacyInterOpController.php index dc97375c975..72693f84b94 100644 --- a/app/Http/Controllers/LegacyInterOpController.php +++ b/app/Http/Controllers/LegacyInterOpController.php @@ -10,7 +10,6 @@ use App\Jobs\Notifications\ForumTopicReply; use App\Jobs\RegenerateBeatmapsetCover; use App\Libraries\Chat; -use App\Libraries\UserBestScoresCheck; use App\Models\Beatmap; use App\Models\Beatmapset; use App\Models\Chat\Channel; @@ -297,17 +296,6 @@ public function userBatchSendMessage() return response()->json($results); } - public function userBestScoresCheck($id) - { - $user = User::findOrFail($id); - - foreach (Beatmap::MODES as $mode => $_v) { - (new UserBestScoresCheck($user))->run($mode); - } - - return ['success' => true]; - } - public function userIndex($id) { $user = User::findOrFail($id); diff --git a/app/Jobs/RemoveBeatmapsetBestScores.php b/app/Jobs/RemoveBeatmapsetBestScores.php index 568bea841c6..c72c47e9d75 100644 --- a/app/Jobs/RemoveBeatmapsetBestScores.php +++ b/app/Jobs/RemoveBeatmapsetBestScores.php @@ -6,7 +6,6 @@ namespace App\Jobs; use App\Libraries\Elasticsearch\BoolQuery; -use App\Libraries\Elasticsearch\Es; use App\Models\Beatmap; use App\Models\Beatmapset; use App\Models\Score\Best\Model; @@ -57,13 +56,6 @@ public function handle() $query->filter(['terms' => ['beatmap_id' => $beatmapIds]]); $query->filter(['range' => ['score_id' => ['lte' => $this->maxScoreIds[$mode]]]]); - // TODO: do something with response? - Es::getClient('scores')->deleteByQuery([ - 'index' => $GLOBALS['cfg']['osu']['elasticsearch']['prefix']."high_scores_{$mode}", - 'body' => ['query' => $query->toArray()], - 'client' => ['ignore' => 404], - ]); - $class = Model::getClass($mode); // Just delete until no more matching rows. $query = $class diff --git a/app/Libraries/UserBestScoresCheck.php b/app/Libraries/UserBestScoresCheck.php deleted file mode 100644 index 6f7c4b41db1..00000000000 --- a/app/Libraries/UserBestScoresCheck.php +++ /dev/null @@ -1,116 +0,0 @@ -. Licensed under the GNU Affero General Public License v3.0. -// See the LICENCE file in the repository root for full licence text. - -namespace App\Libraries; - -use App\Libraries\Elasticsearch\BoolQuery; -use App\Libraries\Elasticsearch\Es; -use App\Libraries\Elasticsearch\Search; -use App\Libraries\Elasticsearch\Sort; -use App\Libraries\Search\BasicSearch; -use App\Models\Score\Best; -use App\Models\User; - -/** - * Used to check the best scores for a user if it exists in elasticsearch but not longer - * exists in the database. A mismatch tends to break the current pager, so this can be run to - * fix it by deleting the invalid score from elasticsearch. - * - * e.g. - * (new UserBestScoresCheck(User::find($user_id)))->run($mode). - */ -class UserBestScoresCheck -{ - /** @var int */ - public $dbIdsFound; - /** @var int */ - public $esIdsFound; - - /** @var User */ - private $user; - - /** - * @param User $user The User to check the scores for. - */ - public function __construct(User $user) - { - $this->user = $user; - } - - /** - * Checks for extraneous scores in Elasticsearch. - * - * @param string $mode The game mode. - * @return array List of score_ids that exist in Elasticsearch but not the database. - */ - public function check(string $mode) - { - $this->dbIdsFound = 0; - $this->esIdsFound = 0; - - $clazz = Best\Model::getClass($mode); - - $search = $this->newSearch($mode); - $cursor = [0]; - - $missingIds = []; - - while ($cursor !== null) { - $esIds = $search->searchAfter(array_values($cursor))->response()->ids(); - $this->esIdsFound += count($esIds); - - $dbIds = $clazz::default()->whereIn('score_id', $esIds)->pluck('score_id')->all(); - $this->dbIdsFound += count($dbIds); - - $missingIds = array_merge( - $missingIds, - array_values(array_diff($esIds, $dbIds)) - ); - - $cursor = $search->getSortCursor(); - } - - return $missingIds; - } - - /** - * Removes extraneous scores from Elasticsearch. - * - * @param string $mode The game mode. - * @param array $ids List of score_ids to remove. - * @return array The raw response from Elasticsearch. - */ - public function removeFromEs(string $mode, array $ids) - { - return Es::getClient('scores')->deleteByQuery([ - 'index' => $GLOBALS['cfg']['osu']['elasticsearch']['prefix']."high_scores_{$mode}", - 'body' => ['query' => ['terms' => ['score_id' => $ids]]], - ]); - } - - /** - * Checks for extraneous scores in Elasticsearch and removes them. - * - * @param string $mode The game mode. - * @return array The raw response from Elasticsearch. - */ - public function run(string $mode) - { - return $this->removeFromEs($mode, $this->check($mode)); - } - - private function newSearch(string $mode): Search - { - $index = $GLOBALS['cfg']['osu']['elasticsearch']['prefix']."high_scores_{$mode}"; - - $search = new BasicSearch($index, "user_best_scores_check_{$mode}"); - $search->connectionName = 'scores'; - - return $search - ->sort(new Sort('score_id', 'asc')) - ->size(Es::CHUNK_SIZE) - ->query((new BoolQuery())->filter(['term' => ['user_id' => $this->user->getKey()]])); - } -} diff --git a/config/elasticsearch.php b/config/elasticsearch.php index 0ce6f8eba79..203283c7207 100644 --- a/config/elasticsearch.php +++ b/config/elasticsearch.php @@ -20,9 +20,6 @@ 'default' => array_merge($defaults, [ 'hosts' => $parseHosts('ES_HOST'), ]), - 'scores' => array_merge($defaults, [ - 'hosts' => $parseHosts('ES_SCORES_HOST'), - ]), 'solo_scores' => array_merge($defaults, [ 'hosts' => $parseHosts('ES_SOLO_SCORES_HOST'), ]), diff --git a/docker-compose.yml b/docker-compose.yml index 6d9ce7103d9..68636414721 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,6 @@ x-env: &x-env DB_CONNECTION_STRING: Server=db;Database=osu;Uid=osuweb; DB_HOST: db ES_HOST: http://elasticsearch:9200 - ES_SCORES_HOST: http://elasticsearch:9200 ES_SOLO_SCORES_HOST: http://elasticsearch:9200 GITHUB_TOKEN: "${GITHUB_TOKEN}" NOTIFICATION_REDIS_HOST: redis diff --git a/routes/web.php b/routes/web.php index 9d1f9cb1712..54ed56d460d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -563,7 +563,6 @@ Route::post('generate-notification', 'LegacyInterOpController@generateNotification'); Route::post('index-beatmapset/{beatmapset}', 'LegacyInterOpController@indexBeatmapset'); Route::post('/refresh-beatmapset-cache/{beatmapset}', 'LegacyInterOpController@refreshBeatmapsetCache'); - Route::post('/user-best-scores-check/{user}', 'LegacyInterOpController@userBestScoresCheck'); Route::post('user-send-message', 'LegacyInterOpController@userSendMessage'); Route::post('user-batch-mark-channel-as-read', 'LegacyInterOpController@userBatchMarkChannelAsRead'); Route::post('user-batch-send-message', 'LegacyInterOpController@userBatchSendMessage');