<commit_before><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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\Es;
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 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)
    {
        $clazz = Best\Model::getClassByString($mode);

        $esIds = $this->user->beatmapBestScoreIds($mode, 100);
        $dbIds = $clazz::default()->whereIn('score_id', $esIds)->pluck('score_id')->all();

        return array_values(array_diff($esIds, $dbIds));
    }

    /**
     * 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)<commit_msg>Increse number of user score elasticsearch cleanup per run<commit_after><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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\Es;
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 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)
    {
        $clazz = Best\Model::getClassByString($mode);

        $esIds = $this->user->beatmapBestScoreIds($mode, 2000);
        $dbIds = $clazz::default()->whereIn('score_id', $esIds)->pluck('score_id')->all();

        return array_values(array_diff($esIds, $dbIds));
    }

    /**
     * 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)
{'fraction_non_alphanumeric': 0.11169590643274854, 'fraction_numerical': 0.003216374269005848, 'mean_word_length': 2.9367088607594938, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1993458', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1013, 'n_words': 361}