RedBeanPHP 慢 R::exportAll()

RedBeanPHP slow R::exportAll()

我正在使用 RedBeanPHP 连接到 Postgres 数据库,但是对于其他简单的查询,我的查询时间很慢。这似乎与 RedBean 的 exportAll() 有关。我正在访问类似于 RedBean 的示例:

$books = R::findAll( 'book' );
$beans= R::exportAll( $books );

直接使用查询:

$rows = R::getAll($sql);
$books = R::convertToBeans('books', $rows);
$beans= R::exportAll( $books );

这个查询在 table 上大约需要 1.25 秒,只有 66 个,有两个映射的 tables(在 RedBean 中链接)。这个查询时间看起来很慢,和R::exportAll()直接相关。

版本:

有什么建议吗?

经过大量研究后,我在 'duplicate' section of the RedBeanPHP website 中找到了一个简介,描述如下:

Both dup() and exportAll() need to query the database schema which is slow. To speed up the process you can pass a database schema:

R::$duplicationManager->setTables( $schema ); To obtain the schema use:

$schema = R::$duplicationManager->getSchema(); You can now use this schema to feed it to setTables(). R::duplicate() and

R::exportAll() both use this schema.

这正是我所经历的,但由于 $duplicationManager 现在是私有变量 (Found here in the API),我无法访问 R::$duplicationManager->getSchema()

幸运的是 API 文档中有一个 'getDuplicationManager()' 函数,因此非常成功:

$schema = R::getDuplicationManager()->getSchema();
R::getDuplicationManager()->setTables($schema);

这使我的时间减少到约 0.14 秒,这更合理。