Sorry for opening the threat again, i need a fix if its possible for a problem.
When i change LEFT OUTER to INNER after the else { code the server has lower cpu load at all but some messages in inbox are shown as unread even if you read them many times. do you know how i could solve this?
if( isset($secret) && $secret <> '' ) {
$this->dao->join( $this->getTable_messages() . ' as m', 't.i_thread_id = m.fk_i_thread_id AND ((t.i_from_user_id = ' . $user_id . ' AND m.i_type = 1 OR t.i_to_user_id = ' . $user_id . ' AND m.i_type = 0) OR (t.s_from_secret = "' . $secret . '" AND m.i_type = 1 OR t.s_to_secret = "' . $secret . '" AND m.i_type = 0))', 'INNER' );
} else {
$this->dao->join( $this->getTable_messages() . ' as m', 't.i_thread_id = m.fk_i_thread_id AND ((t.i_from_user_id = ' . $user_id . ' AND m.i_type = 1 OR t.i_to_user_id = ' . $user_id . ' AND m.i_type = 0))', 'INNER' );
}
Also any other way than changing to INNER to make this query run faster? If i make it INNER it will not send the message.
public function getThreadById( $id ) {
$this->dao->select('t.i_thread_id, t.fk_i_item_id, t.i_from_user_id, t.s_from_user_name, t.s_from_user_email, t.s_from_secret, t.i_from_user_notify, t.i_to_user_id, t.s_to_user_name, t.s_to_user_email, t.s_to_secret, t.i_to_user_notify, t.s_title, t.d_datetime, count(m.pk_i_id) as i_count, t.i_flag');
$this->dao->from( $this->getTable_threads() . ' as t' );
$this->dao->join( $this->getTable_messages() . ' as m', 't.i_thread_id = m.fk_i_thread_id', 'LEFT OUTER' );