<commit_before><?php

namespace Lorry\Presenter\Debug;

use Analog;
use Lorry\Presenter;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RegexIterator;
use RecursiveRegexIterator;

class CacheWarmer extends Presenter {

	public function get() {
		$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('../app/templates'));
		$results = new RegexIterator($iterator, '/^.+\.twig$/i', RecursiveRegexIterator::GET_MATCH);

		$time = microtime(true);

		$this->twig->clearCacheFiles();
		Analog::info('Cleared Twig cache');

		$i = 0;
		foreach($results as $file => $array) {
			$filename = substr($file, 17);
			$this->twig->loadTemplate($filename);
			$i++;
		}
		Analog::info('Cached '.$i.' Twig templates');

		$duration = round((microtime(true) - $time) / 1000, 5);
		if(!$duration) {
			$duration = '<1';
		}
		
		header('Content-Type: text/plain');
		echo 'Done. Cleared cache and recached '.$i.' templates in '.$duration.'s.';
	}
<commit_msg>make cache warmer not delete the .gitignore<commit_after><?php

namespace Lorry\Presenter\Debug;

use Analog;
use Lorry\Presenter;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RegexIterator;
use RecursiveRegexIterator;

class CacheWarmer extends Presenter {

	public function get() {

		header('Content-Type: text/plain');
		
		$cache = $this->twig->getCache();
		if(!$cache) {
			echo 'Cache is not in use.';
			return;
		}

		$this->twig->clearTemplateCache();
		$cache = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cache), RecursiveIteratorIterator::LEAVES_ONLY);
		$templates = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('../app/templates'), RecursiveIteratorIterator::LEAVES_ONLY);
		
		$time = microtime(true);
		foreach($cache as $file) {
			if(!$file->isFile() || $file->getBasename() === '.gitignore') {
				continue;
			}
			unlink($file->getPathname());
		}
		Analog::info('Cleared Twig cache');

		$i = 0;
		foreach($templates as $file) {
			if(!$file->isFile() || $file->getExtension() !== 'twig') {
				continue;
			}
			$this->twig->loadTemplate(substr($file->getPathname(), strlen('../app/templates/')));
			$i++;
		}
		Analog::info('Cached '.$i.' Twig templates');

		$duration = round((microtime(true) - $time) / 1000, 5);
		if(!$duration) {
			$duration = '<1';
		}
		
		echo 'Done. Cleared cache and recached '.$i.' templates in '.$duration.'s.';
	}

{'fraction_non_alphanumeric': 0.17129821650767316, 'fraction_numerical': 0.006636250518457071, 'mean_word_length': 4.596287703016241, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, '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': '4536159', 'n_tokens_mistral': 901, 'n_tokens_neox': 790, 'n_words': 170}