I am using this lib to improve performance of my app by reducing number of DB queries.
It wold be great to split features of collector to two methods:
- collect - current implementation - used to collect associations
- fetch/load - allows to fetch associations to reduce number of queries. (returns void)
Why to split:
collect, because it has to return results need to accept 'single path' like `car->engine->parts) where each of elements is child of previous one.
fetch in opposite side should allow to handle 'tree' path:
$paths = [
'engine' => ['parts'],
'fuel'
];
As a result it will fetch:
- engine of car (and used parts)
- fuel type of car
I think that there will not be any way to optimize it (at least I dont know how) , so under the hood it may just do
$collector->collect($car, ['engine', 'parts'];
$collector->collect($car, ['fuel'];
Do you think it may be a 'common/practice' use case, to be worth to add to library?
Classes used in example
class Car
{
protected $engine;
private $fuel;
public function __construct(Engine $engine = null, Fuel $fuel = null)
{
$this->engine = $engine;
$this->fuel = $fuel;
}
public function getEngine()
{
return $this->engine;
}
public function getFuel()
{
return $this->fuel;
}
}
class Engine
{
public $parts;
public function __construct(array $parts)
{
$this->parts = $parts;
}
}
class Fuel
{
protected $name;
public function __construct(string $name)
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
}
I am using this lib to improve performance of my app by reducing number of DB queries.
It wold be great to split features of collector to two methods:
Why to split:
collect, because it has to return results need to accept 'single path' like `car->engine->parts) where each of elements is child of previous one.fetchin opposite side should allow to handle 'tree' path:As a result it will fetch:
I think that there will not be any way to optimize it (at least I dont know how) , so under the hood it may just do
Do you think it may be a 'common/practice' use case, to be worth to add to library?
Classes used in example