Merge pull request 'release 1.6.5 : trending — seul /trending génère le cache' (#75) from dev into main

release 1.6.5 : trending — seul /trending génère le cache
This commit was merged in pull request #75.
This commit is contained in:
2026-05-15 16:20:16 +00:00
5 changed files with 12 additions and 21 deletions
+8
View File
@@ -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é
+1 -11
View File
@@ -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) {
+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);
+1 -1
View File
@@ -1 +1 @@
1.6.4
1.6.5
+1 -1
View File
@@ -159,7 +159,7 @@ function _renderCard(array $post, array $privateCats, array $allCats, \Parsedown
<?php if (!empty($popularPosts)): ?>
<section class="home-section">
<h2 class="home-section-title">
Tendances <span class="home-section-title-sub">· 1 heure</span>
Meilleures audiences <span class="home-section-title-sub">· 1 heure</span>
</h2>
<div class="post-grid">
<?php foreach ($popularPosts as $_pp): ?>