Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/171457

Change subject: Various DB query cleanups
......................................................................

Various DB query cleanups

* Fixed timestamp escaping in handleFailingRecipient()
* Use selectRowCount() to avoid scanning more rows than needed
* Only do the query in handleFailingRecipient() if there is a bouncer trigger 
threshold

Change-Id: I103e97621b1b84faf5105d30453cc71f536d227b
---
M includes/BounceHandlerActions.php
M includes/ProcessBounceEmails.php
2 files changed, 20 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BounceHandler 
refs/changes/57/171457/1

diff --git a/includes/BounceHandlerActions.php 
b/includes/BounceHandlerActions.php
index f4cd92c..34234e9 100644
--- a/includes/BounceHandlerActions.php
+++ b/includes/BounceHandlerActions.php
@@ -44,23 +44,25 @@
         * @return bool
         */
        public function handleFailingRecipient( array $failedUser ) {
-               $originalEmail = $failedUser['rawEmail'];
-               $currentTime = wfTimestamp();
-               $bounceValidPeriod = wfTimestamp( $currentTime - 
$this->bounceRecordPeriod );
-               $dbr = ProcessBounceEmails::getBounceRecordDB( DB_SLAVE, 
$this->wikiId );
-               $res = $dbr->selectRow( 'bounce_records',
-                       array( 'total_count' => 'COUNT(*)' ),
-                       array(
-                               'br_user_email' => $originalEmail,
-                               'br_timestamp >= ' . $dbr->addQuotes( 
wfTimestamp( $bounceValidPeriod ) )
-                       ),
-                       __METHOD__
-               );
+               if ( $this->bounceHandlerUnconfirmUsers ) {
+                       $originalEmail = $failedUser['rawEmail'];
+                       $bounceValidPeriod = time() - 
$this->bounceRecordPeriod; // Unix
 
-               if( $res !== false && ( $res->total_count >= 
$this->bounceRecordLimit ) && $this->bounceHandlerUnconfirmUsers ) {
-                       $this->unSubscribeUser( $failedUser );
-               } else {
-                       wfDebugLog( 'BounceHandler',"Error fetching the count 
of past bounces for user $originalEmail" );
+                       $dbr = ProcessBounceEmails::getBounceRecordDB( 
DB_SLAVE, $this->wikiId );
+
+                       $totalBounces = $dbr->selectRowCount( 'bounce_records',
+                               array( '*' ),
+                               array(
+                                       'br_user_email' => $originalEmail,
+                                       'br_timestamp >= ' . $dbr->addQuotes( 
$dbr->timestamp( $bounceValidPeriod ) )
+                               ),
+                               __METHOD__,
+                               array( 'LIMIT' => $this->bounceRecordLimit )
+                       );
+
+                       if ( $totalBounces >= $this->bounceRecordLimit ) {
+                               $this->unSubscribeUser( $failedUser );
+                       }
                }
 
                return true;
diff --git a/includes/ProcessBounceEmails.php b/includes/ProcessBounceEmails.php
index daa58d3..920824c 100644
--- a/includes/ProcessBounceEmails.php
+++ b/includes/ProcessBounceEmails.php
@@ -65,8 +65,8 @@
                        );
                        $dbw->insert( 'bounce_records', $rowData, __METHOD__ );
 
-                       $takeBounceActions = new BounceHandlerActions( $wikiId, 
$wgBounceRecordPeriod, $wgBounceRecordLimit,
-                       $wgBounceHandlerUnconfirmUsers );
+                       $takeBounceActions = new BounceHandlerActions( $wikiId,
+                               $wgBounceRecordPeriod, $wgBounceRecordLimit, 
$wgBounceHandlerUnconfirmUsers );
                        $takeBounceActions->handleFailingRecipient( $failedUser 
);
                        return true;
                } else {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I103e97621b1b84faf5105d30453cc71f536d227b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

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

Reply via email to