From 1978fbc48f691b9e0e5b5637c1f9b14ed8dd8af9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 13 Jul 2014 00:44:49 +0200 Subject: [PATCH] [ticket/305] Simplify method get_global_id() B3P-305 --- portal/fetch_posts.php | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/portal/fetch_posts.php b/portal/fetch_posts.php index 4f2ae521..9073685f 100644 --- a/portal/fetch_posts.php +++ b/portal/fetch_posts.php @@ -443,20 +443,7 @@ class fetch_posts { if (!empty($this->where_string) || ($row = $this->cache->get('_forum_id_first_forum_post')) === false) { - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type = ' . FORUM_POST . ' - ' . str_replace('t.', '', $this->where_string) . ' - ORDER BY forum_id'; - $result = $this->db->sql_query_limit($sql, 1); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (empty($this->where_string)) - { - // Cache first forum ID for one day = 86400 s - $this->cache->put('_forum_id_first_forum_post', $row, 86400); - } + $row = $this->get_first_forum_id(); } if (empty($row)) @@ -469,6 +456,31 @@ class fetch_posts return true; } + /** + * Gets the first forum_id of FORUM_POST type forums + * + * @return array Database row of query + */ + protected function get_first_forum_id() + { + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST . ' + ' . str_replace('t.', '', $this->where_string) . ' + ORDER BY forum_id'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (empty($this->where_string)) + { + // Cache first forum ID for one day = 86400 s + $this->cache->put('_forum_id_first_forum_post', $row, 86400); + } + + return $row; + } + /** * Resets constraints that might have been set before *