0

当我从数据库中抓取时,如果我有一个大约 1k 标记的结果集,我就想到了一些事情。

如果我使用 Doctrine(v1.2)_Pager 每页限制为 25 个。它是否将从数据库中提取的数据量减少到仅 25 个。或者它仍然抓取整个数据集然后减少它?

实现如下:

$perPage = 25;
$numPageLinks = 25;

$pager = new Doctrine_Pager($q, $input->page, $perPage);

$result = $pager->execute(array(), Doctrine::HYDRATE_ARRAY);

$pagerRange = new Doctrine_Pager_Range_Sliding(
    array('chunk' => $numPageLinks), $pager
);

$pagerUrlBase = '...';

$pagerLayout = new Doctrine_Pager_Layout(
    $pager, $pagerRange, $pagerUrlBase);

$pagerLayout->setTemplate('...');
$pagerLayout->setSelectedTemplate(
    '...'
);
$pagerLayout->setSeparatorTemplate('...');

$this->view->records = $result;
4

2 回答 2

2

Doctrine 的寻呼机只会请求 25 条记录。

您可能会将它与类似的东西混淆,Zend_Paginator_Array它需要一个完整的数组并根据配置对其进行修剪。

于 2012-04-23T17:08:15.827 回答
1

I recommend that you enable mysql query log, and tail the resulting log file. With it you can see the exact queries being issued for each request. As Mike B stated, Doctrine_Pager will issue a pagination query which will result in a limit, offset combination, but you may see other queries you didn't expect by tailing your query log file.

For example, while tailing the log file I was surprised to find that the Doctrine unlink methods were being duplicated. I still haven't figure out if it was Doctrine or Symfony issuing the duplicate delete queries, so I just wrote my own unlink which improved database/application performance.

于 2012-04-23T17:18:14.107 回答