refactor : trending — seul /trending génère le cache, les consommateurs lisent (v1.6.5)

Page d'accueil et /tendances lisent uniquement le cache trending_{period}.json
produit par le flux RSS /trending?period=…. Aucun parsing de logs en dehors du
flux RSS. Rubrique renommée "Meilleures audiences · 1 heure".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 18:19:10 +02:00
parent d0b486f11c
commit e19d20ca17
5 changed files with 12 additions and 21 deletions
+1 -8
View File
@@ -8,7 +8,6 @@ require_once BASE_PATH . '/src/auth.php';
require_once BASE_PATH . '/src/SiteSettings.php';
require_once BASE_PATH . '/config/config.php';
require_once BASE_PATH . '/src/ArticleManager.php';
require_once BASE_PATH . '/src/TrendingParser.php';
const TENDANCES_PERIODS = [
'10m' => ['seconds' => 600, 'label' => '10 dernières minutes', 'short' => '10 min'],
@@ -33,19 +32,13 @@ $seconds = TENDANCES_PERIODS[$period]['seconds'];
$label = TENDANCES_PERIODS[$period]['label'];
$cacheTtl = max(60, min(28800, (int) ($seconds / 5)));
// Cache partagé avec trending.php
@mkdir(DATA_PATH . '/_cache', 0755, true);
// Lecture seule du cache généré par /trending?period=…
$cacheFile = DATA_PATH . '/_cache/trending_' . $period . '.json';
$topPaths = null;
if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheTtl) {
$topPaths = json_decode((string) file_get_contents($cacheFile), true) ?: null;
}
if ($topPaths === null) {
$parser = new TrendingParser('/var/log/apache2', apacheAccessLog());
$topPaths = $parser->top(time() - $seconds, 50);
@file_put_contents($cacheFile, json_encode($topPaths));
}
// Index slug → article
$articleManager = new ArticleManager(DATA_PATH);