From 17652df9f90180ba0551a04a6997d6f8b69828bb Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 21 Oct 2012 17:57:54 +0200 Subject: [PATCH] Cache performer of a LogEntry to load it only once from the database Change-Id: If920ba0a29b8c9b04705a20db5d8f9528b251fe5 --- includes/logging/LogEntry.php | 39 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 2ca525e159..1f94b43a89 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -175,6 +175,7 @@ class DatabaseLogEntry extends LogEntryBase { /// Database result row. protected $row; + protected $performer; protected function __construct( $row ) { $this->row = $row; @@ -232,17 +233,20 @@ class DatabaseLogEntry extends LogEntryBase { } public function getPerformer() { - $userId = (int) $this->row->log_user; - if ( $userId !== 0 ) { // logged-in users - if ( isset( $this->row->user_name ) ) { - return User::newFromRow( $this->row ); - } else { - return User::newFromId( $userId ); + if( !$this->performer ) { + $userId = (int) $this->row->log_user; + if ( $userId !== 0 ) { // logged-in users + if ( isset( $this->row->user_name ) ) { + $this->performer = User::newFromRow( $this->row ); + } else { + $this->performer = User::newFromId( $userId ); + } + } else { // IP users + $userText = $this->row->log_user_text; + $this->performer = User::newFromName( $userText, false ); } - } else { // IP users - $userText = $this->row->log_user_text; - return User::newFromName( $userText, false ); } + return $this->performer; } public function getTarget() { @@ -287,14 +291,17 @@ class RCDatabaseLogEntry extends DatabaseLogEntry { } public function getPerformer() { - $userId = (int) $this->row->rc_user; - if ( $userId !== 0 ) { - return User::newFromId( $userId ); - } else { - $userText = $this->row->rc_user_text; - // Might be an IP, don't validate the username - return User::newFromName( $userText, false ); + if( !$this->performer ) { + $userId = (int) $this->row->rc_user; + if ( $userId !== 0 ) { + $this->performer = User::newFromId( $userId ); + } else { + $userText = $this->row->rc_user_text; + // Might be an IP, don't validate the username + $this->performer = User::newFromName( $userText, false ); + } } + return $this->performer; } public function getTarget() { -- 2.20.1