From edeecb8cf9a147dad3357a8bc6da5db4d64cae2a Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 20 Dec 2023 19:19:35 +0100 Subject: [PATCH] feat: re-add post access counter for get_post function --- www/mysql_adapter.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/www/mysql_adapter.php b/www/mysql_adapter.php index a05eb5b..80dc64a 100644 --- a/www/mysql_adapter.php +++ b/www/mysql_adapter.php @@ -229,12 +229,26 @@ class MySQLAdapter { function get_post_by_path($post_path, $with_subposts = false, $with_settings = true) { - $qry = "SELECT * FROM posts WHERE post_path = ?"; + $qry = " + WITH selected_post AS ( + SELECT * + FROM posts WHERE post_path = ? + ), post_count_data AS ( + SELECT pac.post_path AS post_path, sum(path_access_count) AS post_access_counter + FROM path_access_counts AS pac + INNER JOIN selected_post ON pac.post_path = selected_post.post_path + WHERE agent LIKE 'user%' + GROUP BY pac.post_path + ) + SELECT * + FROM selected_post + LEFT JOIN post_count_data ON post_count_data.post_path = selected_post.post_path"; + $post_path = $this->_sanitize_path($post_path); $post_data = $this->_exec($qry, "s", $post_path)->fetch_assoc(); + $post_data = $this->_normalize_post_data($post_data); - $post_data['post_path'] = $post_path; if(!$post_data['found']) {