Changed use of tag_summary to use change_tag with GROUP_CONCAT()
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 15 Nov 2013 07:23:36 +0000 (23:23 -0800)
committerSpringle <springle@wikimedia.org>
Sun, 17 Nov 2013 06:37:08 +0000 (06:37 +0000)
* Added buildGroupConcatField() method to the DB classes

bug: 53577
Change-Id: I976f297653880e66af429ba9b622a954fefcc512

includes/ChangeTags.php
includes/db/Database.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php

index 7ec641d..3c734c4 100644 (file)
@@ -193,10 +193,9 @@ class ChangeTags {
                        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.
index c677d74..e2c59ed 100644 (file)
@@ -2079,6 +2079,29 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                return 'CONCAT(' . implode( ',', $stringList ) . ')';
        }
 
+       /**
+        * 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
         *
index 97070fb..6b4113e 100644 (file)
@@ -1354,6 +1354,13 @@ class DatabaseOracle extends DatabaseBase {
                return $this->mServer;
        }
 
+       public function buildGroupConcatField(
+               $delim, $table, $field, $conds = '', $join_conds = array()
+       ) {
+               $fld = "LISTAGG($field," . $this->addQuotes( $delim ) . ") WITHIN GROUP (ORDER BY $field)";
+               return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
+       }
+
        public function getSearchEngine() {
                return 'SearchOracle';
        }
index 72371a2..4688000 100644 (file)
@@ -1431,6 +1431,13 @@ SQL;
                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';
        }
index 79a3b1e..84f1bcf 100644 (file)
@@ -828,6 +828,13 @@ class DatabaseSqlite extends DatabaseBase {
                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