diff --git a/www/actions/comment_delete.php b/www/actions/comment_delete.php index 6937d09..360bf1b 100644 --- a/www/actions/comment_delete.php +++ b/www/actions/comment_delete.php @@ -55,9 +55,18 @@ $db->query($sql, __FILE__, __LINE__); -// parent neu kompilieren +// parent neu kompilieren => replaced with cache clearing +// @since 24.11.2024 Using new caching system instead of recompiling if($rs['board'] != 'f' || $rs['parent_id'] > 1) { - Comment::compile_template($rs['thread_id'], $rs['parent_id'], $rs['board']); + require_once INCLUDES_DIR.'comments_cache.inc.php'; + // Clear cache for the deleted comment and its parent + CommentsCache::clearCommentCache($_POST['id'], $rs['board'], $smarty); + CommentsCache::clearCommentCache($rs['parent_id'], $rs['board'], $smarty); + + if (DEVELOPMENT) { + error_log(sprintf('[DEBUG] <%s:%d> Cleared caches after deleting comment %d (parent: %d, board: %s)', + __FILE__, __LINE__, $_POST['id'], $rs['parent_id'], $rs['board'])); + } } // todo: wenns ein thread war, redirecten auf die Übersicht oder Startseite diff --git a/www/includes/forum.inc.php b/www/includes/forum.inc.php index 9a54842..2bd3010 100644 --- a/www/includes/forum.inc.php +++ b/www/includes/forum.inc.php @@ -838,7 +838,7 @@ static function post($parent_id, $board, $user_id, $text, $msg_users=NULL) */ static function update($comment_id, $comment_data_updated) { - global $db, $user, $notification; + global $db, $user, $notification, $smarty; $sql = 'UPDATE comments SET @@ -852,12 +852,19 @@ static function update($comment_id, $comment_data_updated) if ($db->num($updateResult) > 0) { - // FIXME needs to recompile the thread as well - otherwise edited comment shown in old position (IneX, 07.05.2020) - - /** Smarty Comment Templates neu Kompilieren */ - self::compile_template($_POST['thread_id'], $comment_id, $_POST['board']); // sich selbst - self::compile_template($_POST['thread_id'], $_POST['parent_id'], $_POST['board']); // alter parent - self::compile_template($_POST['thread_id'], $_POST['parent_id'], $_POST['board']); // neuer Parent + /** Clear comment caches for edited comment and affected parents + * Using new caching system instead of recompiling templates + * @since 24.11.2024 Replaced compile_template with cache clearing + */ + require_once INCLUDES_DIR.'comments_cache.inc.php'; + CommentsCache::clearCommentCache($comment_id, $_POST['board'], $smarty); // The edited comment + CommentsCache::clearCommentCache($_POST['parent_id'], $_POST['board'], $smarty); // Old parent (if changed) + // Note: Thread cache clearing not needed as thread itself wasn't modified + + if (DEVELOPMENT) { + error_log(sprintf('[DEBUG] <%s:%d> Cleared caches for comment %d and parent %d on board %s', + __METHOD__, __LINE__, $comment_id, $_POST['parent_id'], $_POST['board'])); + } } else { header('Location: '.base64_decode($_POST['url'])); // redirect user back where he came from exit; diff --git a/www/includes/smarty.inc.php b/www/includes/smarty.inc.php index eb4a1cf..677b85b 100644 --- a/www/includes/smarty.inc.php +++ b/www/includes/smarty.inc.php @@ -725,11 +725,12 @@ class Smarty_Resource_Comments extends Smarty_Resource_Custom * * @author [z]biko * @author IneX - * @version 3.0 + * @version 4.0 * @since 1.0 `[z]biko` function added * @since 2.0 `26.10.2018` `IneX` various optimizations, structured html (schema.org) * @since 2.1 `22.01.2020` `IneX` Fix sizeof() to only be called when variable is an array, and therefore guarantee it's Countable (eliminating parsing warnings) * @since 3.0 `09.05.2020` `IneX` Moved funtion to new Class, renamed "smartyresource_comments_get_template" to "fetch" for compatibility with Smarty 3 + * @since 4.0 `24.11.2024` `Copilot` Updated to use new caching-based rendering system instead of custom compiler * * @param string $tpl_name Smarty Template Name * @param string $tpl_source Pass by reference: Smarty Template-Source (Template content) @@ -738,8 +739,7 @@ class Smarty_Resource_Comments extends Smarty_Resource_Custom * @global object $user Globales Class-Object mit den User-Methoden & Variablen * @uses Comment::isThread() Used to check and - if true - assign self::$comment_thread_id * @uses usersystem::is_loggedin() Used to check and assign a true/false bool to self::$user_is_loggedin - * @uses show_comment_forumthread() - * @uses show_comment_thread() + * @uses render_comment_tree() New caching-based rendering function * @return callable */ protected function fetch($tpl_name, &$tpl_source, &$mtime) @@ -750,15 +750,18 @@ protected function fetch($tpl_name, &$tpl_source, &$mtime) $boardkey_and_commentid = explode('-', $tpl_name); /** Store Board and Comment-ID for futher usage in Class */ - $this->board_key = (sizeof($boardkey_and_commentid) === 2 ? (string)$boardkey_and_commentid[0] : null); + $this->board_key = (sizeof($boardkey_and_commentid) === 2 ? (string)$boardkey_and_commentid[0] : 'f'); $this->comment_id = (sizeof($boardkey_and_commentid) === 2 ? (is_numeric($boardkey_and_commentid[1]) && $boardkey_and_commentid[1] > 0 ? (integer)$boardkey_and_commentid[1] : null) : (integer)$boardkey_and_commentid[0]); $this->user_is_loggedin = $user->is_loggedin(); $this->current_user_id = ($this->user_is_loggedin === true ? $user->id : null); - /** Comment als Tree holen */ - if (!empty($this->board_key) && !empty($this->comment_id)) + /** Comment als Tree holen - using new caching-based approach */ + if (!empty($this->comment_id) && $this->comment_id > 0) { - $tpl_source = sprintf('{show_comments comment_id=%d board=%s}', $this->comment_id, $this->board_key); // smartyresource_comments_get_childposts + // Use new rendering system with caching + // Note: We still use Smarty function call format for backward compatibility + // but the actual rendering uses the new caching system + $tpl_source = sprintf('{render_comment_tree_cached comment_id=%d board="%s"}', $this->comment_id, $this->board_key); $mtime = $this->fetchTimestamp($this->comment_id); } /** Missing or invalid Board or Comment-ID */ @@ -1223,6 +1226,13 @@ function menu($name, &$smarty) $smarty->registerPlugin('function', 'show_comments', 'show_comments_tree'); $smarty->registerPlugin('function', 'show_comment', 'show_comment'); +/** + * Include new caching-based comment rendering system + * @since 24.11.2024 Added for Smarty 3.x compatibility and performance improvement + */ +require_once INCLUDES_DIR.'comments_render.inc.php'; +$smarty->registerPlugin('function', 'render_comment_tree_cached', 'render_comment_tree_smarty_wrapper'); + /** * This tells smarty what resource type to use implicitly. * @link https://www.smarty.net/docs/en/variable.default.resource.type.tpl