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()直接相关。
版本:
- 红豆PHP = 4.3.3
- PostgreSQL = 9.6.2
- PHP = 7.0.15-0ubuntu0.16.04.4
- OS = Ubuntu
有什么建议吗?
经过大量研究后,我在 '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 秒,这更合理。
我正在使用 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()直接相关。
版本:
- 红豆PHP = 4.3.3
- PostgreSQL = 9.6.2
- PHP = 7.0.15-0ubuntu0.16.04.4
- OS = Ubuntu
有什么建议吗?
经过大量研究后,我在 '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 秒,这更合理。