mongor
mongor copied to clipboard
Reusing connection in Hydrator::hydrate
So I was looking at the number of new mongodb instances created, and subsequent mongo socket connections created when using hydrate and I made a small change that seems to be working well. .
Line 7 of Hydrator::hydrate
$models = static::base(get_class($mongor), $results, $mongor->connection);
line 25 of Hydrator::base
private static function base($class, $results, $connection){...
line 25 of Hydrator::base
$model = new $class($connection);
This way the Mongor\model __construct uses the same mongodb instance instead of creating a new connection. From what I've read the connection is the largest part of the mongodb overhead and it seems to be making my code faster. Any thoughts on why this is a bad change?