diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2003-11-22 12:43:07 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2003-11-22 12:43:07 +0000 |
commit | 3cb634c796ee0095b011ab69a773da89b8d8c18c (patch) | |
tree | 497f634b5a704967d7a075d1d1beec8c8216f23a /phpBB/includes/functions_posting.php | |
parent | 60162287524a3073ef17294849f705b0ccfc2ee8 (diff) | |
download | forums-3cb634c796ee0095b011ab69a773da89b8d8c18c.tar forums-3cb634c796ee0095b011ab69a773da89b8d8c18c.tar.gz forums-3cb634c796ee0095b011ab69a773da89b8d8c18c.tar.bz2 forums-3cb634c796ee0095b011ab69a773da89b8d8c18c.tar.xz forums-3cb634c796ee0095b011ab69a773da89b8d8c18c.zip |
go with Ashe's suggestion...
git-svn-id: file:///svn/phpbb/trunk@4676 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_posting.php')
-rw-r--r-- | phpBB/includes/functions_posting.php | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index db8bf52973..3580eb478a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -137,44 +137,25 @@ function update_last_post_information($type, $id) { global $db; - switch ($type) - { - case 'forum': - // Splitted query - performance gain - $sql = 'SELECT MAX(post_time) AS max_post_time FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1 - AND forum_id = ' . $id; - $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); - - $sql = 'SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_time = ' . $row['max_post_time']; - break; - - case 'topic': - $sql = 'SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u - WHERE p.post_approved = 1 - AND p.poster_id = u.user_id - AND p.topic_id = $id - ORDER BY p.post_time DESC"; - break; - - default: - return array(); - } - - $result = $db->sql_query_limit($sql, 1); + $update_sql = array(); + $sql = 'SELECT MAX(post_id) as last_post_id + FROM ' . POSTS_TABLE . " + WHERE post_approved = 1 + AND {$type}_id = $id"; + $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $update_sql = array(); - if ($row) + if (!empty($row['last_post_id'])) { + $sql = 'SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u + WHERE p.poster_id = u.user_id + AND p.post_id = ' . $row['last_post_id']; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $update_sql[] = $type . '_last_post_id = ' . (int) $row['post_id']; $update_sql[] = $type . '_last_post_time = ' . (int) $row['post_time']; $update_sql[] = $type . '_last_poster_id = ' . (int) $row['poster_id']; @@ -187,7 +168,7 @@ function update_last_post_information($type, $id) $update_sql[] = 'forum_last_poster_id = 0'; $update_sql[] = "forum_last_poster_name = ''"; } - + return $update_sql; } |