Skip to content

A free, self-hostable news aggregator…

Fix HTTP cache of user queries (#6718)

Alexandre Alapetitec480e571619c
diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php
index 9ce0d7bd7..5ae57dd65 100644
--- a/app/Models/UserDAO.php
+++ b/app/Models/UserDAO.php
@@ -45,14 +45,33 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
return is_dir(USERS_PATH . '/' . $username);
}
+ /** Update time of the last modification action by the user (e.g., mark an article as read) */
public static function touch(string $username = ''): bool {
- if (!FreshRSS_user_Controller::checkUsername($username)) {
+ if ($username === '') {
$username = Minz_User::name() ?? Minz_User::INTERNAL_USER;
+ } elseif (!FreshRSS_user_Controller::checkUsername($username)) {
+ return false;
}
return touch(USERS_PATH . '/' . $username . '/config.php');
}
+ /** Time of the last modification action by the user (e.g., mark an article as read) */
public static function mtime(string $username): int {
- return @(int)filemtime(USERS_PATH . '/' . $username . '/config.php');
+ return @filemtime(USERS_PATH . '/' . $username . '/config.php') ?: 0;
+ }
+
+ /** Update time of the last new content automatically received by the user (e.g., cron job, WebSub) */
+ public static function ctouch(string $username = ''): bool {
+ if ($username === '') {
+ $username = Minz_User::name() ?? Minz_User::INTERNAL_USER;
+ } elseif (!FreshRSS_user_Controller::checkUsername($username)) {
+ return false;
+ }
+ return touch(USERS_PATH . '/' . $username . '/' . LOG_FILENAME);
+ }
+
+ /** Time of the last new content automatically received by the user (e.g., cron job, WebSub) */
+ public static function ctime(string $username): int {
+ return @filemtime(USERS_PATH . '/' . $username . '/' . LOG_FILENAME) ?: 0;
}
}
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 3e01fe7dd..d066bd254 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -631,11 +631,7 @@ function invalidateHttpCache(string $username = ''): bool {
Minz_Session::_param('touch', uTimeString());
$username = Minz_User::name() ?? Minz_User::INTERNAL_USER;
}
- $ok = @touch(DATA_PATH . '/users/' . $username . '/' . LOG_FILENAME);
- //if (!$ok) {
- //TODO: Display notification error on front-end
- //}
- return $ok;
+ return FreshRSS_UserDAO::ctouch($username);
}
/**
diff --git a/p/api/query.php b/p/api/query.php
index fff48503e..57ec10ff3 100644
--- a/p/api/query.php
+++ b/p/api/query.php
@@ -47,8 +47,13 @@ if (!FreshRSS_Context::hasUserConf() || !FreshRSS_Context::userConf()->enabled)
if (!file_exists(DATA_PATH . '/no-cache.txt')) {
require(LIB_PATH . '/http-conditional.php');
+ $dateLastModification = max(
+ FreshRSS_UserDAO::ctime($user),
+ FreshRSS_UserDAO::mtime($user),
+ @filemtime(DATA_PATH . '/config.php') ?: 0
+ );
// TODO: Consider taking advantage of $feedMode, only for monotonous queries {all, categories, feeds} and not dynamic ones {read/unread, favourites, user labels}
- if (httpConditional(FreshRSS_UserDAO::mtime($user) ?: time(), 0, 0, false, PHP_COMPRESSION, false)) {
+ if (httpConditional($dateLastModification ?: time(), 0, 0, false, PHP_COMPRESSION, false)) {
exit(); //No need to send anything
}
}
diff --git a/p/i/index.php b/p/i/index.php
index fbd9553ad..67536d0ad 100644
--- a/p/i/index.php
+++ b/p/i/index.php
@@ -37,10 +37,11 @@ if (!file_exists($applied_migrations_path)) {
require(LIB_PATH . '/http-conditional.php');
$currentUser = Minz_User::name();
$dateLastModification = $currentUser === null ? time() : max(
- @filemtime(USERS_PATH . '/' . $currentUser . '/' . LOG_FILENAME) ?: 0,
+ FreshRSS_UserDAO::ctime($currentUser),
+ FreshRSS_UserDAO::mtime($currentUser),
@filemtime(DATA_PATH . '/config.php') ?: 0
);
- if (httpConditional($dateLastModification, 0, 0, false, PHP_COMPRESSION, true)) {
+ if (httpConditional($dateLastModification ?: time(), 0, 0, false, PHP_COMPRESSION, true)) {
Minz_Session::init('FreshRSS');
Minz_Session::_param('keepAlive', 1); //To prevent the PHP session from expiring
exit(); //No need to send anything