0

我使用 Doctrine 1.2 执行一个简单的查询。

这是查询。

$cat = Doctrine_Core::getTable('Model_Category')->find($CatID);
if( isset($cat) && $cat->getNode()->hasChildren())
            $this->view->CategoryTree = $cat->getNode()->getChildren();

为什么这么慢?


任何人都有解决方案来获得更好的性能。
谢谢

4

1 回答 1

3

当我对我的应用程序进行基准测试时,我发现使用 Doctrine_Core::HYDRATE_ARRAY 有很大的不同。当仅在 View 中使用时,这通常是有意义的。

如果您需要更复杂的嵌套集,则仅使用 Doctrine_Query 可能是更好的选择。

你想要的可能是这样的查询:

$query = Doctrine_Query::create();
$query->from('Model_Category cat')
    ->leftJoin('cat.Node n')
    ->leftJoin('n.Childre c')
    ->where('count(c.id) > 0')
    ->andWhere('cat.id = ?', $id);
$query->execute(array(1), Doctrine_Core::HYDRATE_ARRAY)

如果您使用 Ubuntu,Xdebug 分析会非常有用:

sudo apt-get install php5-xdebug

然后:

须藤gedit /etc/php5/apache2/conf.d/xdebug.ini

在 xdebug.ini 我有:

zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so
xdebug.profiler_enable=on
xdebug.profiler_output_dir="/tmp/xdebug"
xdebug.profiler_output_name = "cachegrind.out.%H.%R.%t"

记得创建目录:

mkdir /tmp/xdebug

sudo chgrp www-data /tmp/xdebug

chmod 774 /tmp/xdebug

然后我用KCachegrind看输出,希望对你有帮助

于 2011-01-07T21:44:55.357 回答