From e19d20ca1746afaa3bb91f843a1c642e7741521f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drix?= Date: Fri, 15 May 2026 18:19:10 +0200 Subject: [PATCH] =?UTF-8?q?refactor=20:=20trending=20=E2=80=94=20seul=20/t?= =?UTF-8?q?rending=20g=C3=A9n=C3=A8re=20le=20cache,=20les=20consommateurs?= =?UTF-8?q?=20lisent=20(v1.6.5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CHANGELOG.md | 8 ++++++++ public/index.php | 12 +----------- public/tendances.php | 9 +-------- public/version.txt | 2 +- templates/post_list.php | 2 +- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7b644b..d8ba47f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ Format : [Keep a Changelog](https://keepachangelog.com/fr/1.0.0/) — versionnag --- +## [1.6.5] - 2026-05-15 + +### Modifié +- `/tendances` et page d'accueil (rubrique "Meilleures audiences") : lecture seule du cache généré par `/trending?period=…` — plus aucun parsing de logs en dehors du flux RSS +- Rubrique renommée "Meilleures audiences · 1 heure" (ex "Tendances · 10 derniers jours") + +--- + ## [1.6.4] - 2026-05-15 ### Ajouté diff --git a/public/index.php b/public/index.php index 279813e..41e71df 100644 --- a/public/index.php +++ b/public/index.php @@ -3453,22 +3453,12 @@ switch ($action) { $allPostsMap = array_column($allPosts, null, 'uuid'); $_slugMap = array_column($allPosts, null, 'slug'); - // Tendances 1 h — logs Apache (visiteurs uniques, cache 12 min) - require_once BASE_PATH . '/src/TrendingParser.php'; + // Tendances 1 h — lecture seule du cache généré par /trending?period=1h $_trendCache = DATA_PATH . '/_cache/trending_1h.json'; $_trendPaths = null; if (file_exists($_trendCache) && (time() - filemtime($_trendCache)) < 720) { $_trendPaths = json_decode((string) file_get_contents($_trendCache), true) ?: null; } - if ($_trendPaths === null) { - $_tp = new TrendingParser('/var/log/apache2', apacheAccessLog()); - if ($_tp->isReadable()) { - $_trendPaths = $_tp->top(time() - 3600, 20); - @mkdir(DATA_PATH . '/_cache', 0755, true); - @file_put_contents($_trendCache, json_encode($_trendPaths)); - } - unset($_tp); - } if (!empty($_trendPaths)) { foreach ($_trendPaths as $_path => $_cnt) { if (count($popularPosts) >= 6) { diff --git a/public/tendances.php b/public/tendances.php index e7ede92..49788e8 100644 --- a/public/tendances.php +++ b/public/tendances.php @@ -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); diff --git a/public/version.txt b/public/version.txt index 9edc58b..9f05f9f 100644 --- a/public/version.txt +++ b/public/version.txt @@ -1 +1 @@ -1.6.4 +1.6.5 diff --git a/templates/post_list.php b/templates/post_list.php index c3e7e2c..10be95d 100644 --- a/templates/post_list.php +++ b/templates/post_list.php @@ -159,7 +159,7 @@ function _renderCard(array $post, array $privateCats, array $allCats, \Parsedown

- Tendances · 1 heure + Meilleures audiences · 1 heure