I am using RedBeanPHP to connect to a Postgres database, but I am experiencing slow query times for otherwise simple queries. This appears to be related to RedBean's exportAll()
. I am accessing similar to RedBean's example:
$books = R::findAll( 'book' );
$beans= R::exportAll( $books );
Using the query directly with:
$rows = R::getAll($sql);
$books = R::convertToBeans('books', $rows);
$beans= R::exportAll( $books );
This query takes about 1.25 seconds on a table with only 66, with two mapped tables (that are linked in RedBean). This query time seems very slow and directly related to R::exportAll().
Versions:
Any suggestions?
After a ton of research I found a blurb in the 'duplicate' section of the RedBeanPHP website describing the following:
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.
Which is exactly what I experienced, but I was unable to access R::$duplicationManager->getSchema()
due to $duplicationManager now being a private variable (Found here in the API).
Luckily there is a 'getDuplicationManager()' function further down in the API documentation so with great success:
$schema = R::getDuplicationManager()->getSchema();
R::getDuplicationManager()->setTables($schema);
This brought my time down to ~0.14 seconds, which is far more reasonable.