use find_one when loading Monitor to take advantage of caching

This commit is contained in:
Isaac Connor 2018-09-15 09:38:09 -04:00
parent 2b66b28689
commit 1db59283e3
1 changed files with 18 additions and 11 deletions

View File

@ -84,7 +84,10 @@ class Event {
}
public function Monitor() {
return new Monitor( isset($this->{'MonitorId'}) ? $this->{'MonitorId'} : NULL );
if ( isset($this->{'MonitorId'}) ) {
return Monitor::find_one(array('Id'=>$this->{MonitorId}));
}
return new Monitor();
}
public function __call( $fn, array $args){
@ -95,9 +98,13 @@ class Event {
return $this->{$fn};
$backTrace = debug_backtrace();
$file = $backTrace[0]['file'];
$line = $backTrace[0]['line'];
Warning("Unknown function call Event->$fn from $file:$line");
$file = $backTrace[1]['file'];
$line = $backTrace[1]['line'];
Warning("Unknown function call Event->$fn from $file:$line");
Warning(print_r( $this, true ));
}
}
@ -498,7 +505,6 @@ class Event {
}
public static function find( $parameters = null, $options = null ) {
$filters = array();
$sql = 'SELECT * FROM Events ';
$values = array();
@ -526,20 +532,21 @@ class Event {
}
if ( isset($options['limit']) ) {
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
$sql .= ' LIMIT ' . $limit;
$sql .= ' LIMIT ' . $options['limit'];
} else {
$backTrace = debug_backtrace();
$file = $backTrace[1]['file'];
$line = $backTrace[1]['line'];
Error("Invalid value for limit($limit) passed to Event::find from $file:$line");
Error("Invalid value for limit(".$options['limit'].") passed to Event::find from $file:$line");
return array();
}
}
}
$filters = array();
$result = dbQuery($sql, $values);
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Event');
foreach ( $results as $row => $obj ) {
$filters[] = $obj;
$results = $result->fetchALL();
foreach ( $results as $row ) {
$filters[] = new Event($row);
}
return $filters;
}