nextras / dbal

Database Abstraction Layer – concise secure API to construct queries & fetch data
https://nextras.org/dbal
MIT License
79 stars 28 forks source link

Tracy DebugBar disappears when retrieving data from relationship #60

Closed Hologos closed 6 years ago

Hologos commented 7 years ago

Hi,

Tracy DebugBar dissapears if I retrieve data from a relationship. Table sets has ~200 records, table cards has ~30 000 records (some have 300 cards paired to them, some 50). I think it's caused by Nextras\Dbal query panel. I am using "nextras/orm": "3.0.@beta", "nextras/dbal": "3.0.@rc", "tracy/tracy": "~2.4".

Entities definition

<?php
namespace App\Model\Orm;

use Nextras\Orm\Entity\Entity;
use Nextras\Orm\Relationships\OneHasMany;

/**
 * @property int                $id {primary}
 * @property string             $code
 * @property string             $name
 * @property OneHasMany|Card[]  $cards {1:m Card::$set, orderBy=name}
 */
class Set extends Entity
{
}

/**
 * @property string         $id {primary}
 * @property string         $name
 * @property Set            $set {m:1 Set::$cards}
 */
class Card extends Entity
{
}
?>

Sample code

<?php
foreach($this->orm->sets->findAll() as $set)
{
    foreach($set->cards as $card) {}
}
?>
hrach commented 7 years ago

Generally, no ORM is suitable for loading 30 000 entities, it's a bad idea. If you need somehow iterate over all entities, you should do a batch loading with clearing the model (Model::clear()).

To the current issue: it's probably caused by PHP's memory limit. Try inverstigate if there is a message in outputted code, also if it's ok if you increase the limit.

Next, is this a common webpage or CLI script?

Hologos commented 7 years ago

I increased the number of entities loaded and you are indeed correct - it's a memory limit issue. I can see the message now on screen. It somehow died in Tracy and didn't report any message.

I missed the chapter about clearing the model. I will redo the service method, it's supposed to be a cli script.

hrach commented 7 years ago

Maybe this should be somehow fixed - disabling Nette tracy panel in CLI. Will check, reopening for that.

hrach commented 6 years ago

Closing since it may be a convenient to have bluescreen from CLI with the debugging info.