<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\Models\ChatFilter;

class ChatFilters
{
    private $chatFilters;

    public function all()
    {
        if (!isset($this->chatFilters)) {
            $this->fetch();
        }

        return $this->chatFilters;
    }

    public function fetch()
    {
        $localCacheVersion = cache()->get('chat_filters_local_cache_version');
        $localCache = cache()->store(config('cache.local'));

        if ($localCacheVersion === null) {
            $localCacheVersion = hrtime(true);
            cache()->forever('chat_filters_local_cache_version', $localCacheVersion);
        }

        $cachedFilters = $localCache->get('chat_filters') ?? [];

        if (
            array_key_exists('data', $cachedFilters)
            && array_key_exists('version', $cachedFilters)
            && $cachedFilters['version'] === $localCacheVersion
        ) {
                $this->chatFilters = $cachedFilters['data'];
        }

        if ($this->chatFilters === null) {
            $this->chatFilters = ChatFilter::all();
            $localCache->forever('chat_filters', ['version' => $localCacheVersion, 'data' => $this->chatFilters]);
        }
    }

    public function resetCache()
    {
        cache()->put('chat_filters_local_cache_version', hrtime(true));

        $this->chatFilters = null;
    }
}<commit_msg>fix<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\Models\ChatFilter;

class ChatFilters
{
    private $chatFilters;

    public function all()
    {
        if (!isset($this->chatFilters)) {
            $this->fetch();
        }

        return $this->chatFilters;
    }

    public function fetch()
    {
        $localCacheVersion = cache()->get('chat_filters_local_cache_version');
        $localCache = cache()->store(config('cache.local'));

        if ($localCacheVersion === null) {
            $localCacheVersion = hrtime(true);
            cache()->forever('chat_filters_local_cache_version', $localCacheVersion);
        }

        $cachedFilters = $localCache->get('chat_filters');

        if ($cachedFilters === null || $cachedFilters['version'] !== $localCacheVersion)
        {
            $cachedFilters = ['version' => $localCacheVersion, 'data' => ChatFilter::all()];
            $localCache->forever('chat_filters', $cachedFilters);
        }

        $this->chatFilters = $cachedFilters['data'];
    }

    public function resetCache()
    {
        cache()->put('chat_filters_local_cache_version', hrtime(true));

        $this->chatFilters = null;
    }
}
{'fraction_non_alphanumeric': 0.14359682430100104, 'fraction_numerical': 0.001380738695201933, 'mean_word_length': 2.668354430379747, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 36, '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': '4527104', 'n_tokens_mistral': 817, 'n_tokens_neox': 826, 'n_words': 167}