Цитата:
Сообщение от AlexLeonov
Сейчас поставил и на блок от phpBB
Среднее время генерации упало до 0.11 секунды, в чем каждый может убедиться.
Мне кажется, что переезд на новый сервер у Юриста откладывается надолго -))
|
у блока phpbb неоптимизированный запрос и соответственно php код. если поправить текст запроса то производительноть увеличивается в 10-ки раз.
кому интересно вот мой код
PHP код:
<?php
// $Id: newbb_new2.php,v 0.2 2005/10/26 01:44:42 SVL Exp $
// ------------------------------------------------------------------------- //
// RUNCMS //
// //
// Relaible - Unique - Nocost & Simplicity & ease off use //
// < http://www.runcms.org > //
// ------------------------------------------------------------------------- //
// License Type : GPL: See /manual/LICENSES/GPL.txt //
// ------------------------------------------------------------------------- //
// //
// Re-make from newbb_plus //
// By SVL (www.propan-sochi.ru & www.runetcms.ru) //
// HDMan
// [#] исправлен sql запрос и php код
// ------------------------------------------------------------------------- //
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function b_phpBB2_newbb_show($options) {
global $db, $myts, $xoopsConfig, $xoopsUser, $phpbb2_url;
define('IN_PHPBB', true);
include_once XOOPS_ROOT_PATH.'/modules/phpBB2/includes/constants.php';
$block = array();
$block['title'] = _MB_PHPBB2_RECENT;
$extra = '';
$from_forum = intval($options[9]);
if (!empty($from_forum)) {
$extra .= " AND f.forum_id = $from_forum";
}
$from_cat = intval($options[10]);
if (!empty($from_cat)) {
$extra .= " AND f.cat_id = $from_cat";
}
$extraview = ' AND f.auth_view = 0';
if ($xoopsUser) { // level 1 - Admin, 2 - Moder
$userid = $xoopsUser->getVar('uid');
$result = $db->query('SELECT user_level FROM '.USERS_TABLE.' WHERE user_id = '.$userid,false,false,'blocks_',60*10);
if ($result) {
$UL = $db->fetch_assoc($result);
if (($UL['user_level'] == 1) || ($UL['user_level'] == 2))
$extraview = '';
}
}
if ( empty($options[7]) || !is_numeric($options[7]) ) {
$options[7] = 5;
}
$sql = "
SELECT
p.poster_id,
t.topic_id,
f.forum_id,
p.post_time,
t.topic_title,
t.topic_views,
t.topic_replies,
t.topic_last_post_id,
f.forum_name,
f.auth_view
FROM
" . TOPICS_TABLE . " AS t
LEFT JOIN " . POSTS_TABLE . " AS p ON t.topic_last_post_id = p.post_id
LEFT JOIN " . FORUMS_TABLE . " AS f ON t.forum_id =f.forum_id
WHERE
t.forum_id !=0
$extra
$extraview
ORDER BY t.topic_last_post_id DESC
LIMIT 0,".$options[7];
if ( !$query = $db->query($sql,false,false,'blocks_',60*10) ) {
echo "ERROR: $sql<br>".$db->error();
}
if ( $db->num_rows($query) > 0 ) {
$block['content'] = '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="bg2"><tr><td><table width="100%" border="0" cellpadding="4" cellspacing="1"><tr class="bg3">';
// Show Posticon?
if ( $options[8] == 1) {
$block['content'] .= '<td align="center"> </td>';
}
// Show Forum?
if ( $options[4] == 1 ) {
$block['content'] .= '<td align="center"><b>'._MB_PHPBB2_FORUM.'</b></td>';
}
$block['content'] .= '<td align="center"><b>'._MB_PHPBB2_TOPIC.'</b></td>';
// Show Replies?
if ( $options[2] == 1 ) {
$block['content'] .= '<td align="center"><b>'._MB_PHPBB2_RPLS.'</b></td>';
}
// Show Views?
if ( $options[3] == 1 ) {
$block['content'] .= '<td align="center"><b>'._MB_PHPBB2_VIEWS.'</b></td>';
}
// Show Time || Poster?
if ( $options[1] == 1 || $options[0] == 1 ) {
$block['content'] .= '<td align="center"><b>'._MB_PHPBB2_LPOST.'</b></td>';
}
$block['content'] .= '</tr>';
if ( empty($options[5]) || !is_numeric($options[5]) ) {
$options[5] = 33;
}
if ( empty($options[6]) || !is_numeric($options[6]) ) {
$options[6] = 19;
}
$display_count = 0;
while ( list($userid, $topicid, $forumid, $time, $title, $views, $replies, $fpid, $forumname, $auth) = $db->fetch_array($query))
{
if($display_count == $options[7])
break;
$forumname = $myts->makeTboxData4Show($forumname);
$title = $myts->makeTareaData4Show($title);
$time = formatTimestamp($time, "m");
$full_title = $title;
if ( strlen($title) > $options[5] ) {
$title = substr($title, 0, $options[5])."..";
}
$block['content'] .= '<tr class="bg1">';
// Show Posticon?
if ( $options[8] == 1 ) {
$block['content'] .= '<td><img src="/images/subject/icon1.gif" alt="" ></td>';
}
// Show Forum?
if ( $options[4] == 1 ) {
$block['content'] .= '<td><a href="'.$phpbb2_url.'viewforum.php?f='.$forumid.'">'.$forumname.'</a></td>';
}
$block['content'] .= '<td><a href="'.$phpbb2_url.'viewtopic.php?t='.$topicid.'" title="'.$full_title.'">'.$title.'</a>';
$block['content'] .= '<a href="'.$phpbb2_url.'viewtopic.php?p='.$fpid.'#'.$fpid.'" title="'.$full_title.'"> <img src="'.$phpbb2_url.'images/sdb.gif" width="16" height="7" border="0" alt="" ></a></td>';
// Show Replies?
if ( $options[2] == 1 ) {
$block['content'] .= '<td align="center">'.$replies.'</td>';
}
// Show Views?
if ( $options[3] == 1 ) {
$block['content'] .= '<td align="center">'.$views.'</td>';
}
// Show Time || Poster?
if ( $options[1] == 1 || $options[0] == 1 ) {
$block['content'] .= '<td align="right" nowrap>';
if ( $options[0] == 1 ) {
$poster = new XoopsUser($userid);
!$poster->uname() ? $postername = $xoopsConfig['anonymous'] : $postername = $poster->uname();
$postername = $myts->makeTboxData4Show($postername);
if ( strlen($postername) > $options[6] ) {
$postername = substr($postername, 0, $options[6])."..";
}
$block['content'] .= ' <b><a href="/modules/phpBB2/profile.php?mode=viewprofile&u='.$userid.'">'.$postername.'</a></b>';
}
if ( $options[1] == 1 && $options[0] == 1 ) {
$block['content'] .= '<br>';
}
if ( $options[1] == 1 ) {
$block['content'] .= $time;
}
$block['content'] .= '</td>';
}
$display_count++;
} // END WHILE
$block['content'] .= '</tr></table></td></tr><tr class="bg4"><td align="right"><span style="font-weight:bold;">»»</span> <b><a href="' . $phpbb2_url . 'index.php">' . _MB_PHPBB2_VSTFRMS . '</a></b></td></tr></table>';
} else {
$block = false;
}
return $block;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function b_phpBB2_newbb_edit($options) {
global $db, $myts;
define('IN_PHPBB', true);
include XOOPS_ROOT_PATH.'/modules/phpBB2/includes/constants.php';
$form = "";
$form = '<table>';
// SHOW POSTER
if ($options[0] == 1) {
$chk1 = "checked='checked'";
$chk0 = '';
} else {
$chk0 = "checked='checked'";
$chk1 = '';
}
$form .= '<tr><td>' . _MB_PHPBB2_SPOSTER . '</td><td> ' . _NO . '<input type="radio" class="radio" name="options[0]" value="0" '.$chk0.'>' . _YES . '<input type="radio" name="options[0]" value="1" ' . $chk1 . '></td></tr>';
// SHOW TIME
if ($options[1] == 1) {
$chk1 = "checked='checked'";
$chk0 = '';
} else {
$chk0 = "checked='checked'";
$chk1 = '';
}
$form .= '<tr><td>' . _MB_PHPBB2_STIME . '</td><td> ' . _NO . '<input type="radio" class="radio" name="options[1]" value="0" ' . $chk0 . '>' . _YES . '<input type="radio" name="options[1]" value="1" ' . $chk1 . '></td></tr>';
// SHOW REPLIES
if ($options[2] == 1) {
$chk1 = "checked='checked'";
$chk0 = '';
} else {
$chk0 = "checked='checked'";
$chk1 = '';
}
$form .= '<tr><td>' . _MB_PHPBB2_SREPLIES . '</td><td> ' . _NO . '<input type="radio" class="radio" name="options[2]" value="0" ' . $chk0 . '>' . _YES . '<input type="radio" name="options[2]" value="1" ' . $chk1 . '></td></tr>';
// SHOW VIEWS
if ($options[3] == 1) {
$chk1 = "checked='checked'";
$chk0 = '';
} else {
$chk0 = "checked='checked'";
$chk1 = '';
}
$form .= '<tr><td>' . _MB_PHPBB2_SVIEWS . '</td><td> ' . _NO . '<input type="radio" class="radio" name="options[3]" value="0" ' . $chk0 . '>' . _YES . '<input type="radio" name="options[3]" value="1" ' . $chk1 . '></td></tr>';
// SHOW FORUM
if ($options[4] == 1) {
$chk1 = "checked='checked'";
$chk0 = '';
} else {
$chk0 = "checked='checked'";
$chk1 = '';
}
$form .= '<tr><td>' . _MB_PHPBB2_SFORUM . '</td><td> ' . _NO . '<input type="radio" class="radio" name="options[4]" value="0" ' . $chk0 . '>' . _YES . '<input type="radio" name="options[4]" value="1" ' . $chk1 . '></td></tr>';
// TRIM TOPIC
$form .= '<tr><td>' . _MB_PHPBB2_TTOPIC . '</td><td><input type="text" class="text" name="options[5]" value="' . $options[5] . '" size="3"></td></tr>';
// TRIM POSTER
$form .= '<tr><td>' . _MB_PHPBB2_TPOSTER . '</td><td><input type="text" class="text" name="options[6]" value="' . $options[6] . '" size="3"></td></tr>';
// LIMIT TO
$form .= '<tr><td>' . _MB_PHPBB2_LIMIT . '</td><td><input type="text" class="text" name="options[7]" value="' . $options[7] . '" size="3"></td></tr>';
// SHOW POSTICON?
if ($options[8] == 1) {
$chk1 = "checked='checked'";
$chk0 = '';
} else {
$chk0 = "checked='checked'";
$chk1 = '';
}
$form .= '<tr><td>' . _MB_PHPBB2_SICON . '</td><td> ' . _NO . '<input type="radio" class="radio" name="options[8]" value="0" ' . $chk0 . '>' . _YES . '<input type="radio" name="options[8]" value="1" ' . $chk1 . '></td></tr>';
$result = $db->query("SELECT forum_id, forum_name FROM " . FORUMS_TABLE ."",false,false,'blocks_',60*10);
if ($result) {
$form .= '<tr><td>'._MB_PHPBB2_FORUM.'</td><td><select class="select" name="options[9]"><option value="0">' . _ANY . '</option>';
while (list($fid, $fname) = $db->fetch_row($result)) {
$chk = ($options[9] == $fid) ? " selected" : "";
$form .= '<option value="' . $fid . '"' . $chk . '>' . $myts->makeTboxData4PreviewInForm($fname) . '</option>';
}
$form .= '</select></td></tr>';
}
$result = $db->query("SELECT cat_id, cat_title FROM " . CATEGORIES_TABLE . "",false,false,'phpbb_',60*10);
if ($result) {
$form .= '<tr><td>'._MB_PHPBB2_CATEGORY.'</td><td><select class="select" name="options[10]"><option value="0">' . _ANY . '</option>';
while (list($cid, $cname) = $db->fetch_row($result)) {
$chk = ($options[10] == $cid) ? " selected" : "";
$form .= '<option value="' . $cid . '"' . $chk . '>' . $myts->makeTboxData4PreviewInForm($cname) . '</option>';
}
$form .= '</select></td></tr>';
}
$form .= '</table>';
return $form;
}
?>