From ad1c25c7c1a1c9033e4872b825c0b158fc02693a Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 16 Feb 2022 00:38:43 +0100 Subject: [PATCH] performance optimization --- application/Building/Building.php | 38 +++++++++++++++++++-- application/Termination/Termination.php | 12 +++++-- application/Workflowvalue/Workflowvalue.php | 10 ++++-- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/application/Building/Building.php b/application/Building/Building.php index f1594adfe..f8dbfc5a5 100644 --- a/application/Building/Building.php +++ b/application/Building/Building.php @@ -80,21 +80,53 @@ class Building extends mfBaseModel { } public function loadWorkflowItems() { - foreach(WorkflowitemModel::search(["object_type" => "building", "active" => 1]) as $item) { + /*foreach(WorkflowitemModel::search(["object_type" => "building", "active" => 1]) as $item) { $item->setObjectId($this->id); $this->workflowitems[$item->name] = $item; mfValuecache::singleton()->set("wfBuilding-".$item->name, $item); + }*/ + + + $item_ids = []; + + $building_wfitems = mfValuecache::singleton()->get("wfitems-building-active"); + if(!$building_wfitems) { + $building_wfitems = WorkflowitemModel::search(["object_type" => "building", "active" => 1]); + mfValuecache::singleton()->set("wfitems-building-active", $building_wfitems); + } + + foreach($building_wfitems as $item) { + $item->setObjectId($this->id); + $this->workflowitems[$item->name] = $item; + mfValuecache::singleton()->set("wfBuilding-name-".$item->name, $item); + mfValuecache::singleton()->set("wfBuilding-id-".$item->id, $item); + $item_ids[] = $item->id; + } + + foreach($item_ids as $id) { + mfValuecache::singleton()->set("wfItemvalue-item-".$id."-object-".$this->id, new Workflowvalue()); + } + + // get values + $values = WorkflowvalueModel::search(["object_id" => $this->id]); + //var_dump($values);exit; + foreach($values as $value) { + if(array_key_exists($value->item->name, $this->workflowitems)) { + //var_dump($value);exit; + $this->workflowitems[$value->item->name]->setValue($value); + mfValuecache::singleton()->set("wfItemvalue-item-".$value->item_id."-object-".$this->id, $value); + } } } public function getWorkflowvalue($itemname, $type = false) { - $item = mfValuecache::singleton()->get("wfBuilding-".$itemname); + $item = mfValuecache::singleton()->get("wfBuilding-name-".$itemname); if(!$item) { $item = WorkflowitemModel::getFirst(['name' => $itemname]); if(!$item->id) { return null; } - mfValuecache::singleton()->set("wfBuilding-".$itemname, $item); + mfValuecache::singleton()->set("wfBuilding-name-".$itemname, $item); } switch($item->type) { diff --git a/application/Termination/Termination.php b/application/Termination/Termination.php index f17a13f74..50210b2f2 100644 --- a/application/Termination/Termination.php +++ b/application/Termination/Termination.php @@ -308,7 +308,11 @@ class Termination extends mfBaseModel { } if($name == "linework_enabler") { - $this->linework_enabler = new User($this->linework_enabled_by); + $this->linework_enabler = mfValuecache::singleton()->get("Worker-id-".$this->linework_enabled_by); + if(!$this->linework_enabler) { + $this->linework_enabler = new User($this->linework_enabled_by); + mfValuecache::singleton()->set("Worker-id-".$this->linework_enabled_by, $this->linework_enabler); + } return $this->linework_enabler; } @@ -332,9 +336,13 @@ class Termination extends mfBaseModel { $classname = ucfirst($name); $idfield = $name."_id"; - $this->$name = new $classname($this->$idfield); + $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; diff --git a/application/Workflowvalue/Workflowvalue.php b/application/Workflowvalue/Workflowvalue.php index 7df9b4072..3d0480e80 100644 --- a/application/Workflowvalue/Workflowvalue.php +++ b/application/Workflowvalue/Workflowvalue.php @@ -145,7 +145,7 @@ class Workflowvalue extends mfBaseModel { } if($name == "changer") { - $user = mfValuecache::singleton()->get("Worker-id-".$this->changed); + $user = mfValuecache::singleton()->get("Worker-id-".$this->changed_by); if($user) { $this->changer = $user; return $this->changer; @@ -153,7 +153,7 @@ class Workflowvalue extends mfBaseModel { if($this->changed && $this->changed_by) { $this->changer = new User($this->changed_by); if($this->changer->id) { - mfValuecache::singleton()->set("Worker-id-".$this->changed, $this->changer); + mfValuecache::singleton()->set("Worker-id-".$this->changed_by, $this->changer); } return $this->changer; } else { @@ -163,9 +163,13 @@ class Workflowvalue extends mfBaseModel { $classname = ucfirst($name); $idfield = $name."_id"; - $this->$name = new $classname($this->$idfield); + $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;