From 246b50be9c914c5f64ba41eb3dade500f778eebb Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 15 Sep 2018 09:39:04 -0400 Subject: [PATCH] add caching to Server --- web/includes/Server.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web/includes/Server.php b/web/includes/Server.php index 1da08c56a..0b7d72a20 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -1,6 +1,8 @@ null, @@ -10,7 +12,10 @@ class Server { 'zmstats' => 1, 'zmtrigger' => 0, ); + + public function __construct( $IdOrRow = NULL ) { + global $server_cache; $row = NULL; if ( $IdOrRow ) { if ( is_integer($IdOrRow) or ctype_digit($IdOrRow) ) { @@ -26,6 +31,7 @@ class Server { foreach ($row as $k => $v) { $this->{$k} = $v; } + $server_cache[$row['Id']] = $this; } else { $this->{'Name'} = ''; $this->{'Hostname'} = ''; @@ -92,12 +98,12 @@ class Server { } 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 Server::find from $file:$line"); + Error("Invalid value for limit(".$options['limit'].") passed to Server::find from $file:$line"); return array(); } } @@ -110,6 +116,13 @@ class Server { } public static function find_one( $parameters = array() ) { + global $server_cache; + if ( + ( count($parameters) == 1 ) and + isset($parameters['Id']) and + isset($server_cache[$parameters['Id']]) ) { + return $server_cache[$parameters['Id']]; + } $results = Server::find( $parameters, array('limit'=>1) ); if ( ! sizeof($results) ) { return;