jenkins-bot has submitted this change and it was merged.

Change subject: Refactor and simplify changeslist/contribs queries a bit
......................................................................


Refactor and simplify changeslist/contribs queries a bit

Change-Id: Ic19ad7dd2ca10bdfab48a95c7deb1247dc655d47
---
M includes/Hooks.php
1 file changed, 29 insertions(+), 47 deletions(-)

Approvals:
  Ladsgroup: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Hooks.php b/includes/Hooks.php
index 73755d5..b0de940 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -137,43 +137,34 @@
                $threshold = self::getDamagingThreshold( $wgUser );
                $dbr = \wfGetDB( DB_REPLICA );
 
-               $tables[] = 'ores_classification';
                $tables[] = 'ores_model';
+               $tables[] = 'ores_classification';
 
                $fields[] = 'oresc_probability';
                // Add user-based threshold
                $fields[] = $dbr->addQuotes( $threshold ) . ' AS 
ores_threshold';
 
-               $conds[] = '(oresm_name = ' . $dbr->addQuotes( 'damaging' ) .
-                       ' OR oresm_name IS NULL)';
-
-               $conds[] = '(oresm_is_current != 0 OR oresm_is_current IS 
NULL)';
-
-               $join_conds['ores_classification'] = [
-                       'LEFT JOIN',
-                       'rc_this_oldid = oresc_rev ' .
-                       'AND oresc_class = 1'
-               ];
-
-               $join_conds['ores_model'] = [
-                       'LEFT JOIN',
-                       'oresc_model = oresm_id ' .
-                       'AND oresm_is_current = 1'
-               ];
+               $join_conds['ores_model'] = [ 'LEFT JOIN', [
+                       'oresm_is_current' => 1,
+                       'oresm_name' => 'damaging'
+               ] ];
+               $join_conds['ores_classification'] = [ 'LEFT JOIN', [
+                       'oresc_model = oresm_id',
+                       'rc_this_oldid = oresc_rev',
+                       'oresc_class' => 1
+               ] ];
 
                if ( self::isModelEnabled( 'damaging' ) && $opts->getValue( 
'hidenondamaging' ) ) {
-                       // Override the join conditions.
-                       $join_conds['ores_classification'] = [
-                               'INNER JOIN',
-                               'rc_this_oldid = oresc_rev ' .
-                               'AND oresc_class = 1'
-                       ];
-
                        // Filter out non-damaging edits.
                        $conds[] = 'oresc_probability > '
                                . $dbr->addQuotes( $threshold );
                        $conds['rc_patrolled'] = 0;
+
+                       // Performance hacks: add STRAIGHT_JOIN (146111) and 
override the LEFT JOINs
+                       // to be INNER JOINs (T137895)
                        $query_options[] = 'STRAIGHT_JOIN';
+                       $join_conds['ores_model'][0] = 'INNER JOIN';
+                       $join_conds['ores_classification'][0] = 'INNER JOIN';
                }
 
                return true;
@@ -281,44 +272,35 @@
                $threshold = self::getDamagingThreshold( $pager->getUser() );
                $dbr = \wfGetDB( DB_REPLICA );
 
-               $query['tables'][] = 'ores_classification';
                $query['tables'][] = 'ores_model';
+               $query['tables'][] = 'ores_classification';
 
                $query['fields'][] = 'oresc_probability';
                // Add user-based threshold
                $query['fields'][] = $dbr->addQuotes( $threshold ) . ' AS 
ores_threshold';
 
-               $query['conds'][] = '(oresm_name = ' . $dbr->addQuotes( 
'damaging' ) .
-                       ' OR oresm_name IS NULL)';
+               $query['join_conds']['ores_model'] = [ 'LEFT JOIN', [
+                       'oresm_is_current' => 1,
+                       'oresm_name' => 'damaging',
+               ] ];
 
-               $query['conds'][] = '(oresm_is_current != 0 OR oresm_is_current 
IS NULL)';
-
-               $query['join_conds']['ores_classification'] = [
-                       'LEFT JOIN',
-                       'rev_id = oresc_rev ' .
-                       'AND oresc_class = 1'
-               ];
-
-               $query['join_conds']['ores_model'] = [
-                       'LEFT JOIN',
-                       'oresc_model = oresm_id ' .
-                       'AND oresm_is_current = 1'
-               ];
+               $query['join_conds']['ores_classification'] = [ 'LEFT JOIN', [
+                       'oresc_model = oresm_id',
+                       'rev_id = oresc_rev',
+                       'oresc_class' => 1
+               ] ];
 
                if (
                        self::isModelEnabled( 'damaging' ) &&
                        $pager->getContext()->getRequest()->getVal( 
'hidenondamaging' )
                ) {
-                       // Override the join conditions.
-                       $join_conds['ores_classification'] = [
-                               'INNER JOIN',
-                               'rc_this_oldid = oresc_rev ' .
-                               'AND oresc_class = 1'
-                       ];
-
                        // Filter out non-damaging edits.
                        $query['conds'][] = 'oresc_probability > '
                                . $dbr->addQuotes( $threshold );
+
+                       // Performance hack: override the LEFT JOINs to be 
INNER JOINs (T137895)
+                       $query['join_conds']['ores_model'][0] = 'INNER JOIN';
+                       $query['join_conds']['ores_classification'][0] = 'INNER 
JOIN';
                }
                return true;
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic19ad7dd2ca10bdfab48a95c7deb1247dc655d47
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to