performance optimization

This commit is contained in:
Frank Schubert
2022-02-16 00:38:43 +01:00
parent 9ed06991e4
commit ad1c25c7c1
3 changed files with 52 additions and 8 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;