From f025fd3e7be449c06c2e99f77f528f402cd93f72 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Fri, 2 Jul 2021 22:17:33 +0200 Subject: Include category timestamp in ETag response header This commit adds the timestamp of the last modified category to the HTTP ETag response header. Additionally, the code has been optimized. --- core/application.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/application.php b/core/application.php index 280a8e7..5d2b1f4 100644 --- a/core/application.php +++ b/core/application.php @@ -167,22 +167,23 @@ if(Application::get('MIGRATOR.ENABLED')) { #=============================================================================== # Check if "304 Not Modified" and ETag header should be sent #=============================================================================== -if(Application::get('CORE.SEND_304') === TRUE AND !defined('ADMINISTRATION')) { +if(Application::get('CORE.SEND_304') AND !defined('ADMINISTRATION')) { #=========================================================================== - # Select edit time from last edited items (page, post, user) + # Fetch timestamps of the last modified entities #=========================================================================== - $execute = '(SELECT time_update FROM %s ORDER BY time_update DESC LIMIT 1) AS %s'; - - $pageTable = ORM\Repositories\Page::getTableName(); - $postTable = ORM\Repositories\Post::getTableName(); - $userTable = ORM\Repositories\User::getTableName(); - - $pageSQL = sprintf($execute, $pageTable, $pageTable); - $postSQL = sprintf($execute, $postTable, $postTable); - $userSQL = sprintf($execute, $postTable, $postTable); + $query = '(SELECT time_update FROM %s ORDER BY time_update DESC LIMIT 1) AS %s'; + + foreach([ + ORM\Repositories\Category::getTableName(), + ORM\Repositories\Page::getTableName(), + ORM\Repositories\Post::getTableName(), + ORM\Repositories\User::getTableName() + ] as $table) { + $parts[] = sprintf($query, $table, $table); + } - $Statement = $Database->query("SELECT {$pageSQL}, {$postSQL}, {$userSQL}"); + $Statement = $Database->query('SELECT '.implode(',', $parts)); #=========================================================================== # Define HTTP ETag header identifier -- cgit v1.2.3