mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
optimized update_last_post_information query.
git-svn-id: file:///svn/phpbb/trunk@4573 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
7924d903b0
commit
98bd5b74f2
3 changed files with 21 additions and 41 deletions
|
@ -321,7 +321,7 @@ function display_attachments($attachment_data, &$update_count, $force_physical =
|
|||
}
|
||||
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'];
|
||||
|
|
|
@ -137,27 +137,33 @@ function update_last_post_information($type, $id)
|
|||
switch ($type)
|
||||
{
|
||||
case 'forum':
|
||||
$sql_table_add = ', ' . TOPICS_TABLE . ' t';
|
||||
$sql_where_add = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1 AND t.forum_id = ' . (int) $id;
|
||||
$sql_update_table = FORUMS_TABLE;
|
||||
// Anyone having any ideas how to optimize this?
|
||||
// This query is very time consuming on large boards (already optimized this by 50%)
|
||||
$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_table_add = '';
|
||||
$sql_where_add = 'AND p.topic_id = ' . (int) $id;
|
||||
$sql_update_table = TOPICS_TABLE;
|
||||
$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();
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
$row = $db->sql_fetchrow($result);
|
||||
|
@ -356,32 +362,6 @@ function move_uploaded_attachment($upload_mode, $source_filename, &$filedata)
|
|||
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
|
||||
// I am sure i had this grabbed from some site... source: unknown
|
||||
function get_img_size_format($width, $height)
|
||||
|
|
|
@ -683,7 +683,7 @@ class parse_message
|
|||
$error = array();
|
||||
|
||||
$num_attachments = count($this->attachment_data);
|
||||
$this->filename_data['filecomment'] = request_var('filecomment', '');
|
||||
$this->filename_data['filecomment'] = preg_replace('#&(\#[0-9]+;)#', '&\1', request_var('filecomment', ''));
|
||||
$this->filename_data['filename'] = ($_FILES['fileupload']['name'] != 'none') ? trim($_FILES['fileupload']['name']) : '';
|
||||
|
||||
$add_file = (isset($_POST['add_file'])) ? TRUE : FALSE;
|
||||
|
@ -773,7 +773,7 @@ class parse_message
|
|||
|
||||
foreach ($actual_comment_list as $index => $entry)
|
||||
{
|
||||
$this->attachment_data[$index]['comment'] = $entry;
|
||||
$this->attachment_data[$index]['comment'] = preg_replace('#&(\#[0-9]+;)#', '&\1', $entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue