Skip to content

Instantly share code, notes, and snippets.

@tyoro
Created January 17, 2012 09:43
Show Gist options
  • Save tyoro/1625900 to your computer and use it in GitHub Desktop.
Save tyoro/1625900 to your computer and use it in GitHub Desktop.
tiarraMetroの初回ロードのクロスクエリを廃止して、メモリサイズオーバー対策の為に個別にループ化したもの
function getUnreadList( $server = "", $sort = 0 ){
$sql = "SELECT
channel.id,
channel.name,
substring(channel.name, locate('@', channel.name) + 1) as network
FROM channel
WHERE view = ?";
$values = array(1);
if( !empty($server) ){
$sql .= " WHERE name like ? ";
$values[] = "%@".$server;
}
$order = $this->detectOrder($sort);
if (!empty($order)) {
$sql .= $order;
}
$list = $this->_conn->getArray($this->_conn->Prepare($sql), $values);
foreach( $list as $key => $c ){
$sql = "SELECT
count(*) as cnt
FROM channel
LEFT JOIN log ON channel.id = log.channel_id
WHERE channel.readed_on < log.created_on
&& channel.id = ".$c['id'];
$list[ $key ][ 'cnt' ] = $this->_conn->GetOne( $sql );
}
return $list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment