【问题标题】:RedBeanPHP slow R::exportAll()RedBeanPHP 慢 R::exportAll()
【发布时间】:2017-03-06 18:54:03
【问题描述】:

我正在使用 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 个表和两个映射表(在 RedBean 中链接)的表,此查询大约需要 1.25 秒。这个查询时间似乎很慢,并且与 R::exportAll() 直接相关。

版本:

  • RedBeanPHP = 4.3.3
  • PostgreSQL = 9.6.2
  • PHP = 7.0.15-0ubuntu0.16.04.4
  • 操作系统 = Ubuntu

有什么建议吗?

【问题讨论】:

    标签: php postgresql performance redbean


    【解决方案1】:

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

    dup() 和 exportAll() 都需要查询数据库模式,即 慢的。为了加快这个过程,你可以传递一个数据库模式:

    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() 都使用这个模式。

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

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

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

    这将我的时间缩短到了约 0.14 秒,这要合理得多。

    【讨论】:

    • 另外,我在 R::setup(); 和 R::freeze(true); 初始化之后直接添加了这个模式集。我知道我有点担心将这些调用放在哪里,但是您的 RedBean 设置只发生一次,应该只需要设置一次模式。 ** 除非可能,您切换数据库。 **
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多