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:
+1
-11
@@ -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) {
|
||||
|
||||
@@ -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
@@ -1 +1 @@
|
||||
1.6.4
|
||||
1.6.5
|
||||
|
||||
Reference in New Issue
Block a user