UltrasonicNXT has submitted this change and it was merged.

Change subject: Fix bug that's ben breaking chat
......................................................................


Fix bug that's ben breaking chat

Caused by two messages with identical timestamps.

Couple of other cleanups

Change-Id: I0927636920ec3e289a8cb4b8235591d650f35cb1
---
M MediaWikiChat.php
M MediaWikiChatClass.php
M Send.api.php
3 files changed, 17 insertions(+), 4 deletions(-)

Approvals:
  UltrasonicNXT: Verified; Looks good to me, approved



diff --git a/MediaWikiChat.php b/MediaWikiChat.php
index d577baf..d167b9b 100644
--- a/MediaWikiChat.php
+++ b/MediaWikiChat.php
@@ -16,7 +16,7 @@
 $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'MediaWikiChat',
-       'version' => '2.12.0',
+       'version' => '2.12.1',
        'author' => 'Adam Carter/UltrasonicNXT',
        'url' => 'https://www.mediawiki.org/wiki/Extension:MediaWikiChat',
        'descriptionmsg' => 'chat-desc',
diff --git a/MediaWikiChatClass.php b/MediaWikiChatClass.php
index 06faa9e..7fdc1e0 100644
--- a/MediaWikiChatClass.php
+++ b/MediaWikiChatClass.php
@@ -13,10 +13,10 @@
        const TYPE_KICK = 4;
 
        /**
-        * Get the current UNIX time with microseconds (i.e. 138524180871).
+        * Get the current UNIX time with 100th seconds (i.e. 138524180871).
         * Standard UNIX timestamp contains only 10 digits.
         *
-        * @return Integer: current UNIX timestamp + microseconds
+        * @return Integer: current UNIX timestamp + 100th seconds
         */
        static function now() {
                $m = explode( ' ', microtime() );
diff --git a/Send.api.php b/Send.api.php
index 334bde5..dbc8356 100644
--- a/Send.api.php
+++ b/Send.api.php
@@ -14,6 +14,7 @@
 
                        if ( $message != '' ) {
                                $dbw = wfGetDB( DB_MASTER );
+                               $dbr = wfGetDB( DB_SLAVE );
 
                                $id = $user->getId();
                                $timestamp = MediaWikiChat::now();
@@ -24,7 +25,7 @@
                                }
 
                                // Flood check
-                               $res = $dbw->selectField(
+                               $res = $dbr->selectField(
                                        'chat',
                                        array( 'count(*)' ),
                                        array( "chat_timestamp > " . ( 
$timestamp - ( $wgChatFloodSeconds * 100 ) ), " chat_user_id = " . $id ),
@@ -35,6 +36,18 @@
                                        return true;
                                }
 
+                               $lastTimestamp = $dbr->selectField(
+                                       'chat',
+                                       'chat_timestamp',
+                                       array(),
+                                       __METHOD__,
+                                       array( 'ORDER BY' => 'chat_timestamp 
DESC', 'LIMIT' => 1 )
+                               );
+
+                               if ( $timestamp == $lastTimestamp ) {
+                                       $timestamp += 1; // prevent two 
messages with the same timestamp
+                               }
+
                                $dbw->insert(
                                        'chat',
                                        array(

-- 
To view, visit https://gerrit.wikimedia.org/r/152019
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0927636920ec3e289a8cb4b8235591d650f35cb1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiChat
Gerrit-Branch: master
Gerrit-Owner: UltrasonicNXT <adamr_car...@btinternet.com>
Gerrit-Reviewer: UltrasonicNXT <adamr_car...@btinternet.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to