From 31323ce7836242509d681fc5ced665bae0e4eaa7 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 9 Jul 2024 14:43:37 +0200 Subject: [PATCH] Added some caching to Building --- application/Building/Building.php | 49 +++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/application/Building/Building.php b/application/Building/Building.php index 19b14d447..2d6a35804 100644 --- a/application/Building/Building.php +++ b/application/Building/Building.php @@ -242,17 +242,36 @@ class Building extends mfBaseModel { if($this->$name == null) { if($name == "type") { - $this->type = new Buildingtype($this->type_id); + $type = mfValuecache::singleton()->get("mfObjectmodel-Buildingtype-".$this->type_id); + if(!$type) { + $type = new Buildingtype($this->type_id); + mfValuecache::singleton()->set("mfObjectmodel-Buildingtype-".$this->type_id, $type); + } + $this->type = $type; return $this->type; } if($name == "status") { - $this->status = new Buildingstatus($this->status_id); + $status = mfValuecache::singleton()->get("mfObjectmodel-Buildingstatus-".$this->status_id); + if(!$status) { + $status = new Buildingstatus($this->status_id); + mfValuecache::singleton()->set("mfObjectmodel-Buildingstatus-".$this->status_id, $status); + } + $this->status = $status; return $this->status; + + /*$this->status = new Buildingstatus($this->status_id); + return $this->status;*/ } if($name == "pipeworker") { - $this->pipeworker = new Address($this->pipeworker_id); + $pipeworker = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->pipeworker_id); + if(!$pipeworker) { + $pipeworker = new Buildingstatus($this->pipeworker_id); + mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->pipeworker_id, $pipeworker); + } + $this->pipeworker = $pipeworker; + //$this->pipeworker = new Address($this->pipeworker_id); return $this->pipeworker; } @@ -291,16 +310,20 @@ class Building extends mfBaseModel { $this->pipework_enabler = new User($this->pipework_enabled_by); return $this->pipework_enabler; } - - $classname = ucfirst($name); - $idfield = $name."_id"; - $this->$name = new $classname($this->$idfield); - - if($this->$name->id) { - return $this->$name; - } else { - return null; - } + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); + if(!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } } return $this->$name;