MaxSem has uploaded a new change for review.

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


Change subject: Optimize count queries
......................................................................

Optimize count queries

Use nested selects to count the number of rows on server and avoid pointlessly
sending 500 rows to apaches.

Change-Id: I08182b7626dcf0509d1dc5f5aa8e87814c153acc
---
M includes/specials/SpecialUserProfile.php
1 file changed, 16 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/83/86683/1

diff --git a/includes/specials/SpecialUserProfile.php 
b/includes/specials/SpecialUserProfile.php
index c461745..a9a78c3 100644
--- a/includes/specials/SpecialUserProfile.php
+++ b/includes/specials/SpecialUserProfile.php
@@ -40,8 +40,14 @@
                $constraints = array(
                        'limit' => self::LIMIT + 1,
                );
-               $res = $dbr->select( 'recentchanges', 'rc_timestamp', $where, 
__METHOD__, $constraints );
-               return $res->numRows();
+               $innerSelect = $dbr->selectSQLText( 'recentchanges', 
'rc_timestamp', $where, __METHOD__, $constraints );
+               $res = $dbr->query( "SELECT COUNT(*) FROM ($innerSelect) t", 
__METHOD__ );
+               $row = $res->fetchRow();
+               $result = 0;
+               if ( $row ) {
+                       $result = $row[0];
+               }
+               return $result;
        }
 
        /**
@@ -71,8 +77,14 @@
                $constraints = array(
                        'limit' => self::LIMIT + 1,
                );
-               $res = $dbr->select( 'image', 'img_timestamp', $where, 
__METHOD__, $constraints );
-               return $res->numRows();
+               $innerSelect = $dbr->selectSQLText( 'image', 'img_timestamp', 
$where, __METHOD__, $constraints );
+               $res = $dbr->query( "SELECT COUNT(*) FROM ($innerSelect) t", 
__METHOD__ );
+               $row = $res->fetchRow();
+               $result = 0;
+               if ( $row ) {
+                       $result = $row[0];
+               }
+               return $result;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I08182b7626dcf0509d1dc5f5aa8e87814c153acc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to