optimized update_last_post_information query.

git-svn-id: file:///svn/phpbb/trunk@4573 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2003-10-12 09:13:04 +00:00
parent 7924d903b0
commit 98bd5b74f2
3 changed files with 21 additions and 41 deletions

View file

@ -321,7 +321,7 @@ function display_attachments($attachment_data, &$update_count, $force_physical =
} }
else if ($extensions[$attachment['extension']]['upload_icon'] != '') else if ($extensions[$attachment['extension']]['upload_icon'] != '')
{ {
$upload_image = '<img src="' . $phpbb_root_path . 'images/upload_icons/' . trim($extensions[$attachment['extension']]['upload_icon']) . '" alt="" border="0" />'; $upload_image = '<img src="' . $phpbb_root_path . $config['upload_icons_path'] . '/' . trim($extensions[$attachment['extension']]['upload_icon']) . '" alt="" border="0" />';
} }
$filesize = $attachment['filesize']; $filesize = $attachment['filesize'];

View file

@ -137,27 +137,33 @@ function update_last_post_information($type, $id)
switch ($type) switch ($type)
{ {
case 'forum': case 'forum':
$sql_table_add = ', ' . TOPICS_TABLE . ' t'; // Anyone having any ideas how to optimize this?
$sql_where_add = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1 AND t.forum_id = ' . (int) $id; // This query is very time consuming on large boards (already optimized this by 50%)
$sql_update_table = FORUMS_TABLE; $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; break;
case 'topic': case 'topic':
$sql_table_add = ''; $sql = 'SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username
$sql_where_add = 'AND p.topic_id = ' . (int) $id; FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
$sql_update_table = TOPICS_TABLE; WHERE p.post_approved = 1
AND p.poster_id = u.user_id
AND p.topic_id = $id
ORDER BY p.post_time DESC";
break; break;
default: default:
return array(); return array();
} }
$sql = "SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username
FROM " . POSTS_TABLE . ' p, ' . USERS_TABLE . " u $sql_table_add
WHERE p.post_approved = 1
AND p.poster_id = u.user_id
$sql_where_add
ORDER BY p.post_time DESC";
$result = $db->sql_query_limit($sql, 1); $result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
@ -356,32 +362,6 @@ function move_uploaded_attachment($upload_mode, $source_filename, &$filedata)
return; return;
} }
// Delete File
function phpbb_unlink($filename, $mode = 'file')
{
global $config, $user;
$filename = ($mode == 'thumbnail') ? $config['upload_dir'] . '/thumbs/t_' . $filename : $config['upload_dir'] . '/' . $filename;
$deleted = @unlink($filename);
if (file_exists($filename))
{
$filesys = str_replace('/','\\', $filename);
$deleted = @system("del $filesys");
if (file_exists($filename))
{
@chmod($filename, 0777);
if (!($deleted = @unlink($filename)))
{
$deleted = @system("del $filename");
}
}
}
return $deleted;
}
// Calculate the needed size for Thumbnail // Calculate the needed size for Thumbnail
// I am sure i had this grabbed from some site... source: unknown // I am sure i had this grabbed from some site... source: unknown
function get_img_size_format($width, $height) function get_img_size_format($width, $height)

View file

@ -683,7 +683,7 @@ class parse_message
$error = array(); $error = array();
$num_attachments = count($this->attachment_data); $num_attachments = count($this->attachment_data);
$this->filename_data['filecomment'] = request_var('filecomment', ''); $this->filename_data['filecomment'] = preg_replace('#&amp;(\#[0-9]+;)#', '&\1', request_var('filecomment', ''));
$this->filename_data['filename'] = ($_FILES['fileupload']['name'] != 'none') ? trim($_FILES['fileupload']['name']) : ''; $this->filename_data['filename'] = ($_FILES['fileupload']['name'] != 'none') ? trim($_FILES['fileupload']['name']) : '';
$add_file = (isset($_POST['add_file'])) ? TRUE : FALSE; $add_file = (isset($_POST['add_file'])) ? TRUE : FALSE;
@ -773,7 +773,7 @@ class parse_message
foreach ($actual_comment_list as $index => $entry) foreach ($actual_comment_list as $index => $entry)
{ {
$this->attachment_data[$index]['comment'] = $entry; $this->attachment_data[$index]['comment'] = preg_replace('#&amp;(\#[0-9]+;)#', '&\1', $entry);
} }
} }