csgo-league-web icon indicating copy to clipboard operation
csgo-league-web copied to clipboard

web matches cache json folder when have too much files returns a php timeout error

Open 39ma opened this issue 4 years ago • 8 comments

Describe the bug When in app/cache/matches folder stucks too many match json files (like mine had ~2000), then when discord bot creating a server, web return a php error of max execution time.

Possible fix* I fixed it by running bash cronjob to clean old .json files from that folder, and it solved a problem to me. PHP error points to this function. I tested it, DB is answering very fastly, but checking MATCHES_CACHE takes a long time if there are a lot of files.

protected function doesMatchIdExist(int $matchId): bool
    {
        // Check whether the matchId already exists in the database.
        $query = $this->db->query('SELECT matches.matchid FROM matches WHERE matchid = :matchId', [
            ':matchId' => $matchId
        ]);

        $matches = array_filter(scandir(self::MATCHES_CACHE), function ($item) {
            return !is_dir(self::MATCHES_CACHE . "/$item");
        });

        return $query->rowCount() !== 0 || in_array("$matchId.json", $matches);
    }

39ma avatar Oct 07 '20 06:10 39ma