Aaron Schulz has uploaded a new change for review.

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


Change subject: Changed use of tag_summary to use change_tag with GROUP_CONCAT()
......................................................................

Changed use of tag_summary to use change_tag with GROUP_CONCAT()

* Added buildGroupConcatField() method to the DB classes

Change-Id: I976f297653880e66af429ba9b622a954fefcc512
---
M includes/ChangeTags.php
M includes/db/Database.php
M includes/db/DatabasePostgres.php
M includes/db/DatabaseSqlite.php
4 files changed, 40 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/95584/1

diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php
index 7ec641d..3c734c4 100644
--- a/includes/ChangeTags.php
+++ b/includes/ChangeTags.php
@@ -193,10 +193,9 @@
                        throw new MWException( 'Unable to determine appropriate 
JOIN condition for tagging.' );
                }
 
-               // JOIN on tag_summary
-               $tables[] = 'tag_summary';
-               $join_conds['tag_summary'] = array( 'LEFT JOIN', 
"ts_$join_cond=$join_cond" );
-               $fields[] = 'ts_tags';
+               $fields['ts_tags'] = wfGetDB( DB_SLAVE )->buildGroupConcatField(
+                       ',', 'change_tag', 'ct_tag', "ct_$join_cond=$join_cond"
+               );
 
                if ( $wgUseTagFilter && $filter_tag ) {
                        // Somebody wants to filter on a tag.
diff --git a/includes/db/Database.php b/includes/db/Database.php
index c677d74..e2c59ed 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -2080,6 +2080,29 @@
        }
 
        /**
+        * Build a GROUP_CONCAT or equivalent statement for a query.
+        *
+        * This is useful for combining a field for several rows into a single 
string.
+        * NULL values will not appear in the output, duplicated values will 
appear,
+        * and the resulting delimiter-separated values have no defined sort 
order.
+        * Code using the results may need to use the PHP unique() or sort() 
methods.
+        *
+        * @param string $delim Glue to bind the results together
+        * @param string|array $table Table name
+        * @param string $field Field name
+        * @param string|array $conds Conditions
+        * @param string|array $join_conds Join conditions
+        * @return String SQL text
+        * @since 1.23
+        */
+       public function buildGroupConcatField(
+               $delim, $table, $field, $conds = '', $join_conds = array()
+       ) {
+               $fld = "GROUP_CONCAT($field SEPARATOR " . $this->addQuotes( 
$delim ) . ')';
+               return '(' . $this->selectSQLText( $table, $fld, $conds, null, 
array(), $join_conds ) . ')';
+       }
+
+       /**
         * Change the current database
         *
         * @todo Explain what exactly will fail if this is not overridden.
diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php
index e564a16..f956940 100644
--- a/includes/db/DatabasePostgres.php
+++ b/includes/db/DatabasePostgres.php
@@ -1424,6 +1424,13 @@
                return implode( ' || ', $stringList );
        }
 
+       public function buildGroupConcatField(
+               $delimiter, $table, $field, $conds = '', $options = array(), 
$join_conds = array()
+       ) {
+               $fld = "array_to_string(array_agg($field)," . $this->addQuotes( 
$delimiter ) . '))';
+               return '(' . $this->selectSQLText( $table, $fld, $conds, null, 
array(), $join_conds ) . ')';
+       }
+
        public function getSearchEngine() {
                return 'SearchPostgres';
        }
diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php
index 79a3b1e..84f1bcf 100644
--- a/includes/db/DatabaseSqlite.php
+++ b/includes/db/DatabaseSqlite.php
@@ -828,6 +828,13 @@
                return '(' . implode( ') || (', $stringList ) . ')';
        }
 
+       public function buildGroupConcatField(
+               $delim, $table, $field, $conds = '', $join_conds = array()
+       ) {
+               $fld = "group_concat($field," . $this->addQuotes( $delim ) . 
')';
+               return '(' . $this->selectSQLText( $table, $fld, $conds, null, 
array(), $join_conds ) . ')';
+       }
+
        /**
         * @throws MWException
         * @param $oldName

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I976f297653880e66af429ba9b622a954fefcc512
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

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

Reply via email to