From e0551d35fa6d86c74244ee287768e1633254044a Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 18 May 2022 15:45:32 +0200 Subject: [PATCH] Added some linked data in Order to cache --- application/Order/Order.php | 54 ++++++++++++++++++----- application/OrderProduct/OrderProduct.php | 37 ++++++++++++---- application/Product/Product.php | 8 +++- application/Termination/Termination.php | 23 ++++++++-- public/index.php | 13 ++++++ 5 files changed, 111 insertions(+), 24 deletions(-) diff --git a/application/Order/Order.php b/application/Order/Order.php index ae21fa6e9..aec88fabf 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -169,17 +169,24 @@ class Order extends mfBaseModel { } if($name == "owner") { - $this->owner = new Address($this->owner_id); + $this->owner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->owner_id); + if($this->owner === null) { + $this->owner = new Address($this->owner_id); + if($this->owner->id) { + mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->owner_id, $this->owner); + } + } return $this->owner; } - if($name == "contact") { - $this->contact = new Address($this->contact_id); - return $this->contact; - } - if($name == "billingaddress") { - $this->billingaddress = new Address($this->billingaddress_id); + $this->billingaddress = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->billingaddress_id); + if($this->billingaddress === null) { + $this->billingaddress = new Address($this->billingaddress_id); + if($this->billingaddress->id) { + mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->billingaddress_id, $this->billingaddress); + } + } return $this->billingaddress; } @@ -209,24 +216,51 @@ class Order extends mfBaseModel { } if($name == "creator") { - $this->creator = new User($this->create_by); + $this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); + if($this->creator === null) { + $this->creator = new User($this->create_by); + if($this->creator->id) { + mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator); + } + } return $this->creator; } if($name == "editor") { - $this->editor = new User($this->edit_by); + $this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by); + if($this->editor === null) { + $this->editor = new User($this->edit_by); + if($this->editor->id) { + mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor); + } + } return $this->editor; } + $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; + } + + /*$classname = ucfirst($name); + $idfield = $name."_id"; $this->$name = new $classname($this->$idfield); if($this->$name->id) { return $this->$name; } else { return null; - } + }*/ } return $this->$name; diff --git a/application/OrderProduct/OrderProduct.php b/application/OrderProduct/OrderProduct.php index 3dcf5f5cf..b959b3abc 100644 --- a/application/OrderProduct/OrderProduct.php +++ b/application/OrderProduct/OrderProduct.php @@ -42,23 +42,42 @@ class OrderProduct extends mfBaseModel { if($name == "creator") { - if($this->id) { + $this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); + if($this->creator === null) { $this->creator = new User($this->create_by); - return $this->creator; - } else { - return null; + if($this->creator->id) { + mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator); + } } + return $this->creator; } if($name == "editor") { - if($this->id) { + $this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by); + if($this->editor === null) { $this->editor = new User($this->edit_by); - return $this->editor; - } else { - return null; + if($this->editor->id) { + mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor); + } } + return $this->editor; } + $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; + } + + /* $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = new $classname($this->$idfield); @@ -67,7 +86,7 @@ class OrderProduct extends mfBaseModel { return $this->$name; } else { return null; - } + }*/ } return $this->$name; diff --git a/application/Product/Product.php b/application/Product/Product.php index 13259d899..71779737c 100644 --- a/application/Product/Product.php +++ b/application/Product/Product.php @@ -15,7 +15,13 @@ class Product extends mfBaseModel { $this->attributes = []; // get tech attribs - $ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]); + $ptattribs = mfValuecache::singleton()->get("ProducttechAttributes-techid-".$this->producttech_id); + if($ptattribs === null) { + $ptattribs = ProducttechAttributeModel::search(['producttech_id' => $this->producttech_id]); + if(count($ptattribs)) { + mfValuecache::singleton()->set("ProducttechAttributes-techid-".$this->producttech_id, $ptattribs); + } + } // fill atrribs with existing values of product attribs foreach($ptattribs as $pta) { $attrib = ProductAttributeModel::getFirst(['product_id' => $this->id, 'producttechattribute_id' => $pta->id]); diff --git a/application/Termination/Termination.php b/application/Termination/Termination.php index 6a649ddf7..bbc26b685 100644 --- a/application/Termination/Termination.php +++ b/application/Termination/Termination.php @@ -278,7 +278,13 @@ class Termination extends mfBaseModel { if($this->$name == null) { if($name == "status") { - $this->status = TerminationstatusModel::getOne($this->status_id); + $this->status = mfValuecache::singleton()->get("wfStatus-".$this->status_id); + if($this->status === null) { + $this->status = TerminationstatusModel::getOne($this->status_id); + if($this->status->id) { + mfValuecache::singleton()->set("wfStatus-".$this->status_id, $this->status); + } + } return $this->status; } @@ -293,7 +299,14 @@ class Termination extends mfBaseModel { } if($name == "lineworker") { - $this->lineworker = new Address($this->getProperty("building")->lineworker_id); + $lineworker_id = $this->getProperty("building")->lineworker_id; + $this->lineworker = mfValuecache::singleton()->get("mfObjectmodel-Address-$lineworker_id"); + if($this->lineworker === null) { + $this->lineworker = new Address($this->getProperty("building")->lineworker_id); + if($this->lineworker->id) { + mfValuecache::singleton()->set("mfObjectmodel-Address-$lineworker_id", $this->lineworker); + } + } return $this->lineworker; } @@ -316,7 +329,9 @@ class Termination extends mfBaseModel { $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); + if($this->linework_enabler->id) { + mfValuecache::singleton()->set("Worker-id-".$this->linework_enabled_by, $this->linework_enabler); + } } return $this->linework_enabler; } @@ -342,7 +357,7 @@ class Termination extends mfBaseModel { $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); - if(!$this->$name) { + if($this->$name === null) { $this->$name = new $classname($this->$idfield); } diff --git a/public/index.php b/public/index.php index 692c630de..3b2a245c5 100755 --- a/public/index.php +++ b/public/index.php @@ -30,3 +30,16 @@ $request=array_merge($_GET,$_POST); $app=new mfRouter($request); + +if(defined("MFVALUECACHE_DEBUG") && MFVALUECACHE_DEBUG) { + $i = 0; + $cache = mfValuecache::singleton()->getCache(); + echo "
\n";
+  echo "mfValuecache keys total: ".count($cache)."\n";
+  foreach($cache as $key => $value) {
+    echo "\t$i => $key (". gettype($value).")\n";
+    $i++;
+  }
+
+  echo "
"; +} \ No newline at end of file