mongor icon indicating copy to clipboard operation
mongor copied to clipboard

Reusing connection in Hydrator::hydrate

Open srhyne opened this issue 12 years ago • 0 comments

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?

srhyne avatar Nov 23 '12 17:11 srhyne