From 7bf38af1a45d3d858f0831bf467ef31082896d59 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 19 Sep 2008 17:10:29 +0200 Subject: [PATCH] Enhanced search performance in disk logstream, specially when filtering in LARGE files! --- src/classes/logstream.class.php | 2 +- src/classes/logstreamdisk.class.php | 10 ++++++---- src/index.php | 9 ++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index 4ceafaf..4b4399f 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -656,8 +656,8 @@ abstract class LogStream { // "+", ); - $this->_filters[$tmpKeyName][$iNum][FILTER_VALUE] = preg_replace( $searchArray, $replaceArray, $this->_filters[$tmpKeyName][$iNum][FILTER_VALUE] ); // $this->_filters[$tmpKeyName][$iNum][FILTER_VALUE] = str_replace( '+', ' ', $this->_filters[$tmpKeyName][$iNum][FILTER_VALUE]); + $this->_filters[$tmpKeyName][$iNum][FILTER_VALUE] = preg_replace( $searchArray, $replaceArray, $this->_filters[$tmpKeyName][$iNum][FILTER_VALUE] ); // --- } diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index 3eefe23..c7d2a0a 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -234,7 +234,7 @@ class LogStreamDisk extends LogStream { $ret = $this->ReadNextForwards($uID, $arrProperitesOut); else $ret = $this->ReadNextBackwards($uID, $arrProperitesOut); - + // Only PARSE on success! if ( $ret == SUCCESS && $bParseMessage) { @@ -243,7 +243,7 @@ class LogStreamDisk extends LogStream { // Run optional Message Parsers now $retParser = $this->_logStreamConfigObj->ProcessMsgParsers($arrProperitesOut[SYSLOG_MESSAGE], $arrProperitesOut); - + // Check if we have to skip the message! if ( $retParser == ERROR_MSG_SKIPMESSAGE ) $ret = $retParser; @@ -523,8 +523,10 @@ class LogStreamDisk extends LogStream { */ public function GetLastPageUID() { - // Obtain last UID if enough records are available! - + // Only perform lastUID scan if there are NO filters, for performance REASONS! + if ( $this->_filters != null ) + return UID_UNKNOWN; + // Helper variables $myuid = -1; $counter = 0; diff --git a/src/index.php b/src/index.php index 3dda9f1..26d30b9 100644 --- a/src/index.php +++ b/src/index.php @@ -230,10 +230,6 @@ if ( isset($content['Sources'][$currentSourceID]) ) // TODO Implement ORDER $stream->SetReadDirection($content['read_direction']); - // Read First and LAST UID's before start reading the stream! - $content['uid_last'] = $stream->GetLastPageUID(); - $content['uid_first'] = $stream->GetFirstPageUID(); - // Set current ID and init Counter $uID = $content['uid_current']; $counter = 0; @@ -830,9 +826,12 @@ if ( isset($content['Sources'][$currentSourceID]) ) // Increment Counter $counter++; } while ($counter < $content['ViewEntriesPerPage'] && ($ret = $stream->ReadNext($uID, $logArray)) == SUCCESS); - //print_r ( $content['syslogmessages'] ); + // Move below processing - Read First and LAST UID's before start reading the stream! + $content['uid_last'] = $stream->GetLastPageUID(); + $content['uid_first'] = $stream->GetFirstPageUID(); + if ( $content['main_recordcount'] == -1 || $content['main_recordcount'] > $content['ViewEntriesPerPage'] ) { // Enable Pager in any case here!