UltrasonicNXT has uploaded a new change for review. https://gerrit.wikimedia.org/r/181593
Change subject: Make getInterval return a default value ...................................................................... Make getInterval return a default value When there are no messages in the table Bug: T85077 Change-Id: Ia61db132e80e7ae1e99d516dbc37fc7c52f650b0 --- M MediaWikiChat.php M MediaWikiChatClass.php 2 files changed, 25 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiChat refs/changes/93/181593/1 diff --git a/MediaWikiChat.php b/MediaWikiChat.php index 93d2166..acb948c 100644 --- a/MediaWikiChat.php +++ b/MediaWikiChat.php @@ -16,7 +16,7 @@ $wgExtensionCredits['specialpage'][] = array( 'path' => __FILE__, 'name' => 'MediaWikiChat', - 'version' => '2.12.6', + 'version' => '2.12.7', 'author' => 'Adam Carter/UltrasonicNXT', 'url' => 'https://www.mediawiki.org/wiki/Extension:MediaWikiChat', 'descriptionmsg' => 'chat-desc', diff --git a/MediaWikiChatClass.php b/MediaWikiChatClass.php index 7fdc1e0..1f55555 100644 --- a/MediaWikiChatClass.php +++ b/MediaWikiChatClass.php @@ -136,7 +136,7 @@ static function getInterval() { $dbr = wfGetDB( DB_SLAVE ); $maxInterval = 30 * 1000; - $minInterval = 5 * 1000; + $minInterval = 3 * 1000; $res = $dbr->select( 'chat', @@ -148,30 +148,34 @@ 'ORDER BY' => 'chat_timestamp DESC' ) ); + + if ( $res->numRows() > 3 ){ + $i = 0; - $i = 0; + foreach ( $res as $row ) { + if ( $i == 0 ) { + $latest = $row; + } elseif ( $i == 4 ) { + $oldest = $row; + } + $i++; + } - foreach ( $res as $row ) { - if ( $i == 0 ) { - $latest = $row; - } elseif ( $i == 4 ) { - $oldest = $row; - } - $i++; - } + $latestTime = $latest->chat_timestamp; + $oldestTime = $oldest->chat_timestamp; - $latestTime = $latest->chat_timestamp; - $oldestTime = $oldest->chat_timestamp; + $av = ( $latestTime - $oldestTime ) / 10 ; // divide by 5 to find average, then half - $av = ( $latestTime - $oldestTime ) / 10 ; // divide by 5 to find average, then half + if ( $av > $maxInterval ) { + $av = $maxInterval; + } elseif ( $minInterval ) { + $av = $minInterval; + } - if ( $av > $maxInterval ) { - $av = $maxInterval; - } elseif ( $minInterval ) { - $av = $minInterval; - } - - return $av; + return $av; + } else { + return 7 * 1000 + } } /** -- To view, visit https://gerrit.wikimedia.org/r/181593 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia61db132e80e7ae1e99d516dbc37fc7c52f650b0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiChat Gerrit-Branch: master Gerrit-Owner: UltrasonicNXT <adamr_car...@btinternet.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits