โดยผมได้ทดสอบคิดโคดเพื่อปรับโดยการใช้งาน Event phpbb มาช่วยดังนี้ครับ
โค้ด: เลือกทั้งหมด
public function viewtopic_cache_user_data($event) {
global $auth;
global $phpbb_container;
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
$post_sum = 0;
$ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));
$m_approve_topics_fid_sql = $phpbb_content_visibility->get_global_visibility_sql('post', $ex_fid_ary, 'p.'); // ดึงเเบบ topics เฉพาะ topics ที่มีสิท
$moderator_permissions_forum = $auth->acl_get('m_');
$event['poster_id'];
if ($event['poster_id'] != $this->user->data['user_id'] && $moderator_permissions_forum != 1) {
$where_user_id = ($event['poster_id']) ? ' AND p.poster_id =' . $event['poster_id'] : ' ';
if ($where_user_id != null) {
$sql_ray = array(
'SELECT' => 'DISTINCT count(p.post_id) as count_post ',
'FROM' => array(
POSTS_TABLE => 'p',
),
'WHERE' => $m_approve_topics_fid_sql . $where_user_id . ' AND p.post_id NOT IN (select post_id FROM ' . $this->table_prefix . 'anonymous' . ' WHERE user_id = ' . $event['poster_id'] . ')',
' ORDER_BY' => ' p.post_time DESC',
);
$sql = $this->db->sql_build_query('SELECT', $sql_ray);
//echo $sql."<hr>";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$post_sum = $row['count_post'];
$post_num = $event['user_cache_data'];
$post_num['posts'] = $post_sum;
$event['user_cache_data'] = $post_num;
}
}
}
เช่นว่า ถ้าหาก มี user 20 user มาโพสต์ ก็จะทำการ Query 20 รอบครับ ซึ่งทำให้มีความช้า
จึงอยากทราบว่า ควรจะมีการปรับปรุงอย่างไรครับ