gpt4 book ai didi

php - RedBeanPHP 慢 R::exportAll()

转载 作者:行者123 更新时间:2023-11-29 12:56:16 24 4
gpt4 key购买 nike

我正在使用 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 );

这个查询在一个只有 66 个表的表上花费大约 1.25 秒,有两个映射表(在 RedBean 中链接)。这个查询时间看起来很慢并且与 R::exportAll() 直接相关。

版本:

  • RedBeanPHP = 4.3.3
  • PostgreSQL = 9.6.2
  • PHP = 7.0.15-0ubuntu0.16.04.4
  • 操作系统 = 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.

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

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

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

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

关于php - RedBeanPHP 慢 R::exportAll(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42633372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com