now Caching Preorder load + auto updating attrib inhouse_cabling_supplied

This commit is contained in:
Frank Schubert
2025-09-26 18:36:01 +02:00
parent 1a66a6aa9f
commit 5d9ae37d83
5 changed files with 88 additions and 8 deletions

View File

@@ -149,7 +149,11 @@ class AddressDB {
$log = mfLoghandler::singleton(); $log = mfLoghandler::singleton();
$log->debug(__METHOD__.": =============================== in handleRimoStatusUpdate"); $log->debug(__METHOD__.": =============================== in handleRimoStatusUpdate");
$wohneinheit = mfValuecache::singleton()->get("mfObjectmodel-adb_wohneinheit-$wohneinheit_id");
if(!$wohneinheit) {
$wohneinheit = new ADBWohneinheit($wohneinheit_id); $wohneinheit = new ADBWohneinheit($wohneinheit_id);
if($wohneinheit->id) mfValuecache::singleton()->set("mfObjectmodel-adb_wohneinheit-$wohneinheit_id", $wohneinheit);
}
if(!$wohneinheit->id) { if(!$wohneinheit->id) {
//echo "no wohneinheit\n"; //echo "no wohneinheit\n";
return false; return false;

View File

@@ -999,6 +999,9 @@ class AddressDBController extends mfBaseController {
case 'findBuildings': case 'findBuildings':
$return = $this->findBuildingsApi(); $return = $this->findBuildingsApi();
break; break;
case 'countWithFilter':
$return = $this->countWithFilter();
break;
case 'getUnit': case 'getUnit':
$return = $this->getUnitApi(); $return = $this->getUnitApi();
break; break;
@@ -1020,6 +1023,14 @@ class AddressDBController extends mfBaseController {
$this->returnJson($data); $this->returnJson($data);
} }
private function countWithFilter() {
$filter = $this->getPreparedFilter($this->request->filter);
$filter["netzgebiet_id"] = true;
return ["count" => ADBHausnummerModel::count($filter)];
}
private function updateAddressStatusApi() { private function updateAddressStatusApi() {
$address_id = $this->request->id; $address_id = $this->request->id;

View File

@@ -41,6 +41,11 @@ class Preorder extends mfBaseModel {
if($this->uid === "string") { if($this->uid === "string") {
$this->uid = ""; $this->uid = "";
} }
if($this->id) {
//echo "[{$this->_ruid}] preorder::afterload: adding to cache\n";
mfValuecache::singleton()->set("mfObjectmodel-preorder-" . $this->id, $this);
}
} }
public function beforeSave($_params = []) { public function beforeSave($_params = []) {
@@ -57,6 +62,7 @@ class Preorder extends mfBaseModel {
$this->building = null; $this->building = null;
$this->adb_hausnummer = null; $this->adb_hausnummer = null;
$this->adb_wohneinheit = null; $this->adb_wohneinheit = null;
$this->attribute = null;
$this->services = null; $this->services = null;
$this->ordered_services = null; $this->ordered_services = null;
$this->creator = null; $this->creator = null;
@@ -475,7 +481,11 @@ class Preorder extends mfBaseModel {
return true; return true;
} }
$hausnummer = mfValuecache::singleton()->get("mfObjectmodel-adb_hausnummer-" . $this->adb_hausnummer_id);
if(!$hausnummer) {
$hausnummer = new ADBHausnummer($this->adb_hausnummer_id); $hausnummer = new ADBHausnummer($this->adb_hausnummer_id);
if($hausnummer->id) mfValuecache::singleton()->set("mfObjectmodel-adb_hausnummer-".$this->adb_hausnummer_id, $hausnummer);
}
if(!$hausnummer->id) { if(!$hausnummer->id) {
$this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": hausnummer " . $this->adb_hausnummer_id . " not found!"); $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": hausnummer " . $this->adb_hausnummer_id . " not found!");
return true; return true;
@@ -519,7 +529,11 @@ class Preorder extends mfBaseModel {
return true; return true;
} }
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id); $wohneinheit = mfValuecache::singleton()->get("mfObjectmodel-adb_wohneinheit-" . $this->adb_wohneinheit_id);
if(!$wohneinheit) {
$wohneinheit = new ADBwohneinheit($this->adb_wohneinheit_id);
if($wohneinheit->id) mfValuecache::singleton()->set("mfObjectmodel-adb_wohneinheit-".$this->adb_wohneinheit_id, $wohneinheit);
}
if(!$wohneinheit->id) return true; if(!$wohneinheit->id) return true;
$this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": new wohneinheit status code " . $new_wohneinheit_status->code); $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": new wohneinheit status code " . $new_wohneinheit_status->code);
@@ -536,6 +550,24 @@ class Preorder extends mfBaseModel {
if(is_array($flags) && count($flags)) { if(is_array($flags) && count($flags)) {
foreach($flags as $flag) { foreach($flags as $flag) {
if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_FLAG_MATRIX)) { if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_FLAG_MATRIX)) {
if($flag->code == "145") {
//echo "flag 145\n";
$attribs = $this->getProperty("attribute");
if(!is_array($attribs)) {
$attribs = [];
}
if(!array_key_exists("inhouse_cabling_supplied", $attribs) || $attribs["inhouse_cabling_supplied"] != $flag->value->value) {
$attribs["inhouse_cabling_supplied"] = (int)$flag->value->value;
//echo "[{$this->_ruid}] preorder::aftersave: updating attrib to ".(int)$flag->value->value."\n";
$this->attributes = json_encode($attribs);
$this->save(["no_aftersave" => true]);
//print_r($this->attributes);echo "\n";
}
}
$flag_matrix_item = TT_PREORDER_STATUS_FLAG_MATRIX[$flag->code]; $flag_matrix_item = TT_PREORDER_STATUS_FLAG_MATRIX[$flag->code];
if(!$flag_matrix_item["flag"]) continue; if(!$flag_matrix_item["flag"]) continue;
@@ -1051,7 +1083,7 @@ class Preorder extends mfBaseModel {
public function setStatusFlag($code, $value = 1) { public function setStatusFlag($code, $value = 1) {
if(!$code) return false; if(!$code) return false;
$sflag = PreorderstatusflagModel::getFirst(["code" => $code]); $sflag = PreorderStatusflagModel::getFirst(["code" => $code]);
if(!$sflag) return false; if(!$sflag) return false;
$sflag->preorder_id = $this->id; $sflag->preorder_id = $this->id;
@@ -1503,12 +1535,28 @@ class Preorder extends mfBaseModel {
} }
if($name == "adb_hausnummer") { if($name == "adb_hausnummer") {
$this->adb_hausnummer = new ADBHausnummer($this->adb_hausnummer_id); $hausnummer = mfValuecache::singleton()->get("mfObjectmodel-adb_hausnummer-" . $this->adb_hausnummer_id);
if(!$hausnummer) {
$hausnummer = new ADBHausnummer($this->adb_hausnummer_id);
}
if($hausnummer && $hausnummer->id) {
mfValuecache::singleton()->set("mfObjectmodel-adb_hausnummer-" . $this->adb_hausnummer_id, $hausnummer);
$this->adb_hausnummer = $hausnummer;
}
return $this->adb_hausnummer; return $this->adb_hausnummer;
} }
if($name == "adb_wohneinheit") { if($name == "adb_wohneinheit") {
$this->adb_wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id); $wohneinheit = mfValuecache::singleton()->get("mfObjectmodel-adb_wohneinheit-" . $this->adb_wohneinheit_id);
if(!$wohneinheit) {
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
}
if($wohneinheit && $wohneinheit->id) {
mfValuecache::singleton()->set("mfObjectmodel-adb_wohneinheit-" . $this->adb_wohneinheit_id, $wohneinheit);
$this->adb_wohneinheit = $wohneinheit;
}
return $this->adb_wohneinheit; return $this->adb_wohneinheit;
} }

View File

@@ -267,6 +267,13 @@ class PreorderModel
if ($db->num_rows($res)) { if ($db->num_rows($res)) {
$data = $db->fetch_object($res); $data = $db->fetch_object($res);
// search in cache
$item = mfValuecache::singleton()->get("mfObjectmodel-preorder-".$data->id);
if($item) {
return $item;
}
// if not in cache, load regularly
$item = new Preorder($data); $item = new Preorder($data);
if ($item->id) { if ($item->id) {
return $item; return $item;
@@ -558,11 +565,16 @@ class PreorderModel
while ($data = $db->fetch_object($res)) { while ($data = $db->fetch_object($res)) {
if ($returnArray) { if ($returnArray) {
$items[] = $data; $items[] = $data;
} else {
$item = mfValuecache::singleton()->get("mfObjectmodel-preorder-".$data->id);
if($item) {
$items[] = $item;
} else { } else {
$items[] = new Preorder($data); $items[] = new Preorder($data);
} }
} }
} }
}
return $items; return $items;
} }

View File

@@ -4,6 +4,7 @@ class PreorderStatusflagValue extends mfBaseModel {
private $preorder; private $preorder;
protected function afterSave() { protected function afterSave() {
//echo __METHOD__."\n";
if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) { if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) {
$history = PreorderHistoryModel::create([ $history = PreorderHistoryModel::create([
"preorder_id" => $this->data->preorder_id, "preorder_id" => $this->data->preorder_id,
@@ -15,7 +16,10 @@ class PreorderStatusflagValue extends mfBaseModel {
$history->save(); $history->save();
} }
$this->getProperty("preorder")->afterSave();
$preorder = $this->getProperty("preorder");
//echo "[{$preorder->_ruid}] flagvalue aftersave: loaded preorder\n";
$preorder->afterSave();
} }
public function getProperty($name) { public function getProperty($name) {
@@ -23,6 +27,7 @@ class PreorderStatusflagValue extends mfBaseModel {
$classname = ucfirst($name); $classname = ucfirst($name);
$idfield = $name."_id"; $idfield = $name."_id";
//var_dump(mfValuecache::singleton()->cache["mfObjectmodel-$name-".$this->$idfield]);exit;
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) { if(!$this->$name) {
$this->$name = new $classname($this->$idfield); $this->$name = new $classname($this->$idfield);