diff --git a/src/Xhgui/Profiles.php b/src/Xhgui/Profiles.php index b19e5b3..8ff07d9 100644 --- a/src/Xhgui/Profiles.php +++ b/src/Xhgui/Profiles.php @@ -8,6 +8,11 @@ class Xhgui_Profiles protected $_mapper; + /** + * @var MongoId lastProfilingId + */ + private static $lastProfilingId; + public function __construct(MongoDb $db) { $this->_collection = $db->results; @@ -22,20 +27,18 @@ public function __construct(MongoDb $db) */ public function insert($profile) { - $profile = $this->setProfilingId($profile); + $profile['_id'] = self::getLastProfilingId(); return $this->_collection->insert($profile, array('w' => 0)); } - /** - * Set profiling ID, if it is already initiated - * - * @param array $profile The profile data - * @return array - */ - public function setProfilingId($profile) { - if (!empty(Xhgui_Saver::getLastProfilingId())) { - $profile['_id'] = Xhgui_Saver::getLastProfilingId(); - } - return $profile; - } + /** + * Return profiling ID + * @return MongoId lastProfilingId + */ + public static function getLastProfilingId() { + if (!self::$lastProfilingId) { + self::$lastProfilingId = new MongoId(); + } + return self::$lastProfilingId; + } }