私は CakePHP 2.x を使用しており、多くの投稿を含むスレッドがあり、これをページ分割したいと考えています。しかし、SQL ログを調べると、スレッドのすべての投稿 (25k) に影響する SELECT ステートメントがあります。実際には 20 件の投稿しか表示されていないため、このオーバーヘッドを回避する方法はありますか?
これが私の ThreadsController のコードです
public function view($id = null) {
$this->Thread->id = $id;
$this->paginate = array(
'conditions' => array(
'thread_id' => $id,
),
'order' => array(
'Post.id' => 'DESC')
);
if (!$this->Thread->exists()) {
throw new NotFoundException(__('Invalid thread'));
}
$this->set('thread', $this->Thread->read(null, $id));
$this->set('posts', $this->paginate('Post'));
}
25k 行すべてに影響する SQL クエリは次のとおりです。
選択しPostます。id、Post。user_id、Post。post、Post。created、Post。modified、Post。thread_idからppv3。postsどこにPostでもPost。thread_id= (1)