[心得]全域公告(Global announcement)提升執行效能

網站架設,免費空間申請,架站技術交流區

ETERNAL
 
文章: 2937
註冊時間: 2003-12-03 11:08 pm
性別: 男生

[心得]全域公告(Global announcement)提升執行效能

文章ETERNAL » 2005-09-23 11:20 am

在安裝Global announcement外掛時

其中有一段
在viewforum.php裡面
會加入
代碼: 選擇全部
//
// All GLOBAL announcement data, this keeps GLOBAL announcements
// on each viewforum page ...
//
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username
   FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
   WHERE t.topic_poster = u.user_id
   AND p.post_id = t.topic_last_post_id
   AND p.poster_id = u2.user_id
   AND t.topic_type = " . POST_GLOBAL_ANNOUNCE . "
   ORDER BY t.topic_last_post_id DESC ";
if( !$result = $db->sql_query($sql) )
{
   message_die(GENERAL_ERROR, "Couldn't obtain topic information", "", __LINE__, __FILE__, $sql);
}

$topic_rowset = array();
$total_announcements = 0;
while( $row = $db->sql_fetchrow($result) )
{
   $topic_rowset[] = $row;
   $total_announcements++;
}

$db->sql_freeresult($result);
// End add - Global announcement MOD


其實這一段與下面的SQL敘述重複了
代碼: 選擇全部
//
// All announcement data, this keeps announcements
// on each viewforum page ...
//
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username
   FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
   WHERE t.forum_id = $forum_id
      AND t.topic_poster = u.user_id
      AND p.post_id = t.topic_last_post_id
      AND p.poster_id = u2.user_id
      AND t.topic_type = " . POST_ANNOUNCE . "
   ORDER BY t.topic_last_post_id DESC ";


差別只在t.topic_type判斷條件不同

所以只要把第一段拿掉
第二段敘述中的
代碼: 選擇全部
t.forum_id = $forum_id

改成
代碼: 選擇全部
((t.forum_id = $forum_id AND t.topic_type = " . POST_ANNOUNCE . " ) or t.topic_type = " . POST_GLOBAL_ANNOUNCE . " )


然後把ORDER BY 前面的
代碼: 選擇全部
AND t.topic_type = " . POST_ANNOUNCE . "

刪除掉


代碼: 選擇全部
ORDER BY t.topic_last_post_id DESC ";

改成
代碼: 選擇全部
   ORDER BY t.topic_type DESC,t.topic_last_post_id DESC ";


做完以上步驟可以提升viewforum.php的執行效能

以上是我裝Global announcement的心得
若你論壇的資料不多感覺沒什麼差別,這篇文章看看就好 :mrgreen:



回到 架站討論

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 9 位訪客