Schema: Drop old externallinks columns and indexes
Already dropped from production Also dropping FixExtLinksProtocolRelative as it's not useful anymore and it has been run in previous releases so it's not worth fixing. Bug: T312666 Change-Id: I1dd6e704b34e685ada6e316da11243d10827d769
This commit is contained in:
parent
b241174191
commit
e5eda1c358
20 changed files with 147 additions and 308 deletions
|
|
@ -506,7 +506,6 @@ $wgAutoloadLocalClasses = [
|
|||
'FindOrphanedFiles' => __DIR__ . '/maintenance/findOrphanedFiles.php',
|
||||
'FixDefaultJsonContentPages' => __DIR__ . '/maintenance/fixDefaultJsonContentPages.php',
|
||||
'FixDoubleRedirects' => __DIR__ . '/maintenance/fixDoubleRedirects.php',
|
||||
'FixExtLinksProtocolRelative' => __DIR__ . '/maintenance/fixExtLinksProtocolRelative.php',
|
||||
'FixLegacyEncoding' => __DIR__ . '/maintenance/storage/fixLegacyEncoding.php',
|
||||
'FixMergeHistoryCorruption' => __DIR__ . '/maintenance/fixMergeHistoryCorruption.php',
|
||||
'FixTimestamps' => __DIR__ . '/maintenance/fixTimestamps.php',
|
||||
|
|
@ -2397,7 +2396,6 @@ $wgAutoloadLocalClasses = [
|
|||
'RedisConnectionPool' => __DIR__ . '/includes/libs/redis/RedisConnectionPool.php',
|
||||
'RedisLockManager' => __DIR__ . '/includes/libs/lockmanager/RedisLockManager.php',
|
||||
'RedisPubSubFeedEngine' => __DIR__ . '/includes/rcfeed/RedisPubSubFeedEngine.php',
|
||||
'RefreshExternallinksIndex' => __DIR__ . '/maintenance/refreshExternallinksIndex.php',
|
||||
'RefreshFileHeaders' => __DIR__ . '/maintenance/refreshFileHeaders.php',
|
||||
'RefreshImageMetadata' => __DIR__ . '/maintenance/refreshImageMetadata.php',
|
||||
'RefreshLinks' => __DIR__ . '/maintenance/refreshLinks.php',
|
||||
|
|
|
|||
|
|
@ -1985,7 +1985,7 @@ config-schema:
|
|||
- 1.39: Default has changed to SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
|
||||
and support for SCHEMA_COMPAT_OLD is dropped.
|
||||
ExternalLinksSchemaMigrationStage:
|
||||
default: 769
|
||||
default: 768
|
||||
type: integer
|
||||
description: |-
|
||||
Externallinks table schema migration stage.
|
||||
|
|
|
|||
|
|
@ -42,12 +42,6 @@ use Wikimedia\Rdbms\Platform\ISQLPlatform;
|
|||
* - AbuseFilter extension (Special:BlockedExternalDomains, T337431)
|
||||
*/
|
||||
class LinkFilter {
|
||||
/**
|
||||
* Increment this when makeIndexes output changes. It'll cause
|
||||
* maintenance/refreshExternallinksIndex.php to run from update.php.
|
||||
*/
|
||||
public const VERSION = 1;
|
||||
|
||||
/**
|
||||
* Check whether $content contains a link to $filterEntry
|
||||
*
|
||||
|
|
@ -96,8 +90,6 @@ class LinkFilter {
|
|||
* @return string
|
||||
*/
|
||||
private static function indexifyHost( $host, $reverse = true ) {
|
||||
// NOTE: If you change the output of this method, you'll probably have to increment self::VERSION!
|
||||
|
||||
// Canonicalize.
|
||||
$host = rawurldecode( $host );
|
||||
if ( $host !== '' ) {
|
||||
|
|
@ -187,8 +179,6 @@ class LinkFilter {
|
|||
* Each entry is an array in form of <host,path>
|
||||
*/
|
||||
public static function makeIndexes( $url, $reverseDomain = true ) {
|
||||
// NOTE: If you change the output of this method, you'll probably have to increment self::VERSION!
|
||||
|
||||
// NOTE: refreshExternallinksIndex.php assumes that only protocol-relative URLs return more
|
||||
// than one index, and that the indexes for protocol-relative URLs only vary in the "http://"
|
||||
// versus "https://" prefix. If you change that, you'll likely need to update
|
||||
|
|
|
|||
|
|
@ -3255,7 +3255,7 @@ class MainConfigSchema {
|
|||
* - 1.40: Added
|
||||
*/
|
||||
public const ExternalLinksSchemaMigrationStage = [
|
||||
'default' => SCHEMA_COMPAT_READ_NEW | SCHEMA_COMPAT_WRITE_BOTH,
|
||||
'default' => SCHEMA_COMPAT_READ_NEW | SCHEMA_COMPAT_WRITE_NEW,
|
||||
'type' => 'integer',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ return [
|
|||
'DatabaseReplicaLagCritical' => 30,
|
||||
'MaxExecutionTimeForExpensiveQueries' => 0,
|
||||
'TemplateLinksSchemaMigrationStage' => 768,
|
||||
'ExternalLinksSchemaMigrationStage' => 769,
|
||||
'ExternalLinksSchemaMigrationStage' => 768,
|
||||
'ContentHandlers' => [
|
||||
'wikitext' => [
|
||||
'class' => 'WikitextContentHandler',
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ abstract class DatabaseUpdater {
|
|||
PopulateRevisionLength::class,
|
||||
PopulateRevisionSha1::class,
|
||||
PopulateImageSha1::class,
|
||||
FixExtLinksProtocolRelative::class,
|
||||
PopulateFilearchiveSha1::class,
|
||||
PopulateBacklinkNamespace::class,
|
||||
FixDefaultJsonContentPages::class,
|
||||
|
|
@ -97,7 +96,6 @@ abstract class DatabaseUpdater {
|
|||
AddRFCandPMIDInterwiki::class,
|
||||
PopulatePPSortKey::class,
|
||||
PopulateIpChanges::class,
|
||||
RefreshExternallinksIndex::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ class MysqlUpdater extends DatabaseUpdater {
|
|||
[ 'runMaintenance', MigrateExternallinks::class, 'maintenance/migrateExternallinks.php' ],
|
||||
[ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
|
||||
[ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
|
||||
[ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,11 +201,8 @@ class PostgresUpdater extends DatabaseUpdater {
|
|||
[ 'changeField', 'protected_titles', 'pt_reason_id', 'BIGINT', '' ],
|
||||
[ 'dropDefault', 'protected_titles', 'pt_create_perm' ],
|
||||
[ 'dropFkey', 'externallinks', 'el_from' ],
|
||||
[ 'setDefault', 'externallinks', 'el_from', 0 ],
|
||||
[ 'changeField', 'externallinks', 'el_index_60', 'TEXT', '' ],
|
||||
[ 'renameIndex', 'externallinks', 'externallinks_from_to', 'el_from' ],
|
||||
[ 'renameIndex', 'externallinks', 'externallinks_index', 'el_index' ],
|
||||
[ 'addPgIndex', 'externallinks', 'el_to', '(el_to, el_from)' ],
|
||||
[ 'dropSequence', 'ip_changes', 'ip_changes_ipc_rev_id_seq' ],
|
||||
[ 'changeField', 'ip_changes', 'ipc_hex', 'TEXT', "ipc_hex::TEXT DEFAULT ''" ],
|
||||
[ 'setDefault', 'ip_changes', 'ipc_rev_id', 0 ],
|
||||
|
|
@ -454,6 +451,7 @@ class PostgresUpdater extends DatabaseUpdater {
|
|||
[ 'runMaintenance', MigrateExternallinks::class, 'maintenance/migrateExternallinks.php' ],
|
||||
[ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
|
||||
[ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
|
||||
[ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ class SqliteUpdater extends DatabaseUpdater {
|
|||
[ 'runMaintenance', MigrateExternallinks::class, 'maintenance/migrateExternallinks.php' ],
|
||||
[ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
|
||||
[ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
|
||||
[ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
"comment": "Drop old columns of externallinks (T312666)",
|
||||
"before": {
|
||||
"name": "externallinks",
|
||||
"comment": "Track links to external URLs",
|
||||
"columns": [
|
||||
{
|
||||
"name": "el_id",
|
||||
"type": "integer",
|
||||
"options": { "unsigned": true, "notnull": true, "autoincrement": true }
|
||||
},
|
||||
{
|
||||
"name": "el_from",
|
||||
"type": "integer",
|
||||
"comment": "page_id of the referring page",
|
||||
"options": { "unsigned": true, "notnull": true, "default": 0 }
|
||||
},
|
||||
{
|
||||
"name": "el_to",
|
||||
"type": "blob",
|
||||
"comment": "The external link",
|
||||
"options": { "length": 65530, "notnull": false, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_index",
|
||||
"type": "blob",
|
||||
"comment": "In the case of HTTP URLs, this is the URL with any username or password removed, and with the labels in the hostname reversed and converted to lower case which will allow faster searching for all pages with WHERE clause. Note: If PHP's intl extension is enabled/disabled, maintenance/refreshExternallinksIndex.php needs to be run to refresh this field",
|
||||
"options": { "length": 65530, "notnull": false, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_index_60",
|
||||
"type": "binary",
|
||||
"comment": "'el_index' truncated to 60 bytes to allow for sortable queries that aren't supported by a partial index",
|
||||
"options": { "notnull": true, "length": 60, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_to_domain_index",
|
||||
"type": "binary",
|
||||
"comment": "Indexable domain",
|
||||
"options": { "notnull": true, "length": 255, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_to_path",
|
||||
"type": "blob",
|
||||
"comment": "Path to the external link without considering the domain",
|
||||
"options": { "length": 65530, "notnull": false }
|
||||
}
|
||||
],
|
||||
"indexes": [
|
||||
{ "name": "el_from", "columns": [ "el_from" ], "unique": false },
|
||||
{ "name": "el_to", "columns": [ "el_to", "el_from" ], "unique": false, "options": { "lengths": [ 60, null ] } },
|
||||
{ "name": "el_index", "columns": [ "el_index" ], "unique": false, "options": { "lengths": [ 60 ] } },
|
||||
{ "name": "el_index_60", "columns": [ "el_index_60", "el_id" ], "unique": false },
|
||||
{ "name": "el_from_index_60", "columns": [ "el_from", "el_index_60", "el_id" ], "unique": false },
|
||||
{ "name": "el_to_domain_index_to_path", "columns": [ "el_to_domain_index", "el_to_path" ], "unique": false, "options": { "lengths": [ null, 60 ] } }
|
||||
],
|
||||
"pk": [ "el_id" ]
|
||||
},
|
||||
"after": {
|
||||
"name": "externallinks",
|
||||
"comment": "Track links to external URLs",
|
||||
"columns": [
|
||||
{
|
||||
"name": "el_id",
|
||||
"type": "integer",
|
||||
"options": { "unsigned": true, "notnull": true, "autoincrement": true }
|
||||
},
|
||||
{
|
||||
"name": "el_from",
|
||||
"type": "integer",
|
||||
"comment": "page_id of the referring page",
|
||||
"options": { "unsigned": true, "notnull": true, "default": 0 }
|
||||
},
|
||||
{
|
||||
"name": "el_to_domain_index",
|
||||
"type": "binary",
|
||||
"comment": "Indexable domain",
|
||||
"options": { "notnull": true, "length": 255, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_to_path",
|
||||
"type": "blob",
|
||||
"comment": "Path to the external link without considering the domain",
|
||||
"options": { "length": 65530, "notnull": false }
|
||||
}
|
||||
],
|
||||
"indexes": [
|
||||
{ "name": "el_from", "columns": [ "el_from" ], "unique": false },
|
||||
{ "name": "el_to_domain_index_to_path", "columns": [ "el_to_domain_index", "el_to_path" ], "unique": false, "options": { "lengths": [ null, 60 ] } }
|
||||
],
|
||||
"pk": [ "el_id" ]
|
||||
}
|
||||
}
|
||||
12
maintenance/archives/patch-externallinks-drop-el_to.sql
Normal file
12
maintenance/archives/patch-externallinks-drop-el_to.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
|
||||
-- Source: maintenance/abstractSchemaChanges/patch-externallinks-drop-el_to.json
|
||||
-- Do not modify this file directly.
|
||||
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
|
||||
DROP INDEX el_to ON /*_*/externallinks;
|
||||
DROP INDEX el_index ON /*_*/externallinks;
|
||||
DROP INDEX el_index_60 ON /*_*/externallinks;
|
||||
DROP INDEX el_from_index_60 ON /*_*/externallinks;
|
||||
ALTER TABLE /*_*/externallinks
|
||||
DROP el_to,
|
||||
DROP el_index,
|
||||
DROP el_index_60;
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Fixes any entries for protocol-relative URLs in the externallinks table,
|
||||
* replacing each protocol-relative entry with two entries, one for http
|
||||
* and one for https.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
/**
|
||||
* Maintenance script that fixes any entry for protocol-relative URLs
|
||||
* in the externallinks table.
|
||||
*
|
||||
* @ingroup Maintenance
|
||||
*/
|
||||
class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->addDescription(
|
||||
'Fixes any entries in the externallinks table containing protocol-relative URLs' );
|
||||
}
|
||||
|
||||
protected function getUpdateKey() {
|
||||
return 'fix protocol-relative URLs in externallinks';
|
||||
}
|
||||
|
||||
protected function updateSkippedMessage() {
|
||||
return 'protocol-relative URLs in externallinks table already fixed.';
|
||||
}
|
||||
|
||||
protected function doDBUpdates() {
|
||||
$db = $this->getDB( DB_PRIMARY );
|
||||
if ( !$db->tableExists( 'externallinks', __METHOD__ ) ) {
|
||||
$this->error( "externallinks table does not exist" );
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->output( "Fixing protocol-relative entries in the externallinks table...\n" );
|
||||
$res = $db->newSelectQueryBuilder()
|
||||
->select( [ 'el_from', 'el_to', 'el_index' ] )
|
||||
->from( 'externallinks' )
|
||||
->where( [ 'el_index' . $db->buildLike( '//', $db->anyString() ) ] )
|
||||
->caller( __METHOD__ )->fetchResultSet();
|
||||
$count = 0;
|
||||
foreach ( $res as $row ) {
|
||||
$count++;
|
||||
if ( $count % 100 == 0 ) {
|
||||
$this->output( $count . "\n" );
|
||||
$this->waitForReplication();
|
||||
}
|
||||
$db->insert( 'externallinks',
|
||||
[
|
||||
[
|
||||
'el_from' => $row->el_from,
|
||||
'el_to' => $row->el_to,
|
||||
'el_index' => "http:{$row->el_index}",
|
||||
'el_index_60' => substr( "http:{$row->el_index}", 0, 60 ),
|
||||
],
|
||||
[
|
||||
'el_from' => $row->el_from,
|
||||
'el_to' => $row->el_to,
|
||||
'el_index' => "https:{$row->el_index}",
|
||||
'el_index_60' => substr( "https:{$row->el_index}", 0, 60 ),
|
||||
]
|
||||
], __METHOD__, [ 'IGNORE' ]
|
||||
);
|
||||
$db->delete(
|
||||
'externallinks',
|
||||
[
|
||||
'el_index' => $row->el_index,
|
||||
'el_from' => $row->el_from,
|
||||
'el_to' => $row->el_to
|
||||
],
|
||||
__METHOD__
|
||||
);
|
||||
}
|
||||
$this->output( "Done, $count rows updated.\n" );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$maintClass = FixExtLinksProtocolRelative::class;
|
||||
require_once RUN_MAINTENANCE_IF_MAIN;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
|
||||
-- Source: maintenance/abstractSchemaChanges/patch-externallinks-drop-el_to.json
|
||||
-- Do not modify this file directly.
|
||||
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
|
||||
DROP INDEX el_to;
|
||||
DROP INDEX el_index;
|
||||
DROP INDEX el_index_60;
|
||||
DROP INDEX el_from_index_60;
|
||||
ALTER TABLE externallinks
|
||||
DROP el_to;
|
||||
ALTER TABLE externallinks
|
||||
DROP el_index;
|
||||
ALTER TABLE externallinks
|
||||
DROP el_index_60;
|
||||
|
|
@ -443,9 +443,6 @@ CREATE INDEX pt_timestamp ON protected_titles (pt_timestamp);
|
|||
CREATE TABLE externallinks (
|
||||
el_id SERIAL NOT NULL,
|
||||
el_from INT DEFAULT 0 NOT NULL,
|
||||
el_to TEXT DEFAULT '',
|
||||
el_index TEXT DEFAULT '',
|
||||
el_index_60 TEXT DEFAULT '' NOT NULL,
|
||||
el_to_domain_index TEXT DEFAULT '' NOT NULL,
|
||||
el_to_path TEXT DEFAULT NULL,
|
||||
PRIMARY KEY(el_id)
|
||||
|
|
@ -453,14 +450,6 @@ CREATE TABLE externallinks (
|
|||
|
||||
CREATE INDEX el_from ON externallinks (el_from);
|
||||
|
||||
CREATE INDEX el_to ON externallinks (el_to, el_from);
|
||||
|
||||
CREATE INDEX el_index ON externallinks (el_index);
|
||||
|
||||
CREATE INDEX el_index_60 ON externallinks (el_index_60, el_id);
|
||||
|
||||
CREATE INDEX el_from_index_60 ON externallinks (el_from, el_index_60, el_id);
|
||||
|
||||
CREATE INDEX el_to_domain_index_to_path ON externallinks (el_to_domain_index, el_to_path);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Refresh the externallinks table el_index and el_index_60 from el_to
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
use MediaWiki\ExternalLinks\LinkFilter;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
/**
|
||||
* Maintenance script that refreshes the externallinks table el_index and
|
||||
* el_index_60 from el_to
|
||||
*
|
||||
* @ingroup Maintenance
|
||||
* @since 1.33
|
||||
*/
|
||||
class RefreshExternallinksIndex extends LoggedUpdateMaintenance {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->addDescription(
|
||||
'Refresh the externallinks table el_index and el_index_60 from el_to' );
|
||||
$this->setBatchSize( 10000 );
|
||||
}
|
||||
|
||||
protected function getUpdateKey() {
|
||||
return static::class . ' v' . LinkFilter::VERSION . '+IDN';
|
||||
}
|
||||
|
||||
protected function updateSkippedMessage() {
|
||||
return 'externallinks table indexes up to date.';
|
||||
}
|
||||
|
||||
protected function doDBUpdates() {
|
||||
$dbw = $this->getDB( DB_PRIMARY );
|
||||
if ( !$dbw->tableExists( 'externallinks', __METHOD__ ) ) {
|
||||
$this->error( "externallinks table does not exist" );
|
||||
return false;
|
||||
}
|
||||
$this->output( "Updating externallinks table index fields\n" );
|
||||
|
||||
$minmax = $dbw->selectRow(
|
||||
'externallinks',
|
||||
[ 'min' => 'MIN(el_id)', 'max' => 'MAX(el_id)' ],
|
||||
'',
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
$updated = 0;
|
||||
$deleted = 0;
|
||||
$start = $minmax->min - 1;
|
||||
$last = (int)$minmax->max;
|
||||
while ( $start < $last ) {
|
||||
$end = min( $start + $this->mBatchSize, $last );
|
||||
$this->output( "el_id $start - $end of $last\n" );
|
||||
$res = $dbw->select( 'externallinks', [ 'el_id', 'el_to', 'el_index' ],
|
||||
[
|
||||
"el_id > $start",
|
||||
"el_id <= $end",
|
||||
],
|
||||
__METHOD__,
|
||||
[ 'ORDER BY' => 'el_id' ]
|
||||
);
|
||||
foreach ( $res as $row ) {
|
||||
$newIndexes = LinkFilter::makeIndexes( $row->el_to );
|
||||
if ( !$newIndexes ) {
|
||||
$dbw->delete( 'externallinks', [ 'el_id' => $row->el_id ], __METHOD__ );
|
||||
$deleted++;
|
||||
continue;
|
||||
}
|
||||
$newIndexes2 = [];
|
||||
foreach ( $newIndexes as $newIndex ) {
|
||||
$newIndexes2[] = implode( '', $newIndex );
|
||||
}
|
||||
if ( in_array( $row->el_index, $newIndexes2, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( count( $newIndexes2 ) === 1 ) {
|
||||
$newIndex = $newIndexes2[0];
|
||||
} else {
|
||||
// Assume the scheme is the only difference between the different $newIndexes.
|
||||
// Keep this row's scheme, assuming there's another row with the other scheme.
|
||||
$newIndex = substr( $row->el_index, 0, strpos( $row->el_index, ':' ) ) .
|
||||
substr( $newIndexes2[0], strpos( $newIndexes2[0], ':' ) );
|
||||
}
|
||||
$dbw->update( 'externallinks',
|
||||
[
|
||||
'el_index' => $newIndex,
|
||||
'el_index_60' => substr( $newIndex, 0, 60 ),
|
||||
],
|
||||
[ 'el_id' => $row->el_id ],
|
||||
__METHOD__
|
||||
);
|
||||
$updated++;
|
||||
}
|
||||
$this->waitForReplication();
|
||||
$start = $end;
|
||||
}
|
||||
$this->output( "Done, $updated rows updated, $deleted deleted.\n" );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$maintClass = RefreshExternallinksIndex::class;
|
||||
require_once RUN_MAINTENANCE_IF_MAIN;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
|
||||
-- Source: maintenance/abstractSchemaChanges/patch-externallinks-drop-el_to.json
|
||||
-- Do not modify this file directly.
|
||||
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
|
||||
CREATE TEMPORARY TABLE /*_*/__temp__externallinks AS
|
||||
SELECT el_id, el_from, el_to_domain_index, el_to_path
|
||||
FROM /*_*/externallinks;
|
||||
DROP TABLE /*_*/externallinks;
|
||||
CREATE TABLE /*_*/externallinks ( el_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, el_from INTEGER UNSIGNED DEFAULT 0 NOT NULL, el_to_domain_index BLOB DEFAULT '' NOT NULL, el_to_path BLOB DEFAULT NULL );
|
||||
INSERT INTO /*_*/externallinks ( el_id, el_from, el_to_domain_index, el_to_path )
|
||||
SELECT el_id, el_from, el_to_domain_index, el_to_path
|
||||
FROM /*_*/__temp__externallinks;
|
||||
DROP TABLE /*_*/__temp__externallinks;
|
||||
CREATE INDEX el_from ON /*_*/externallinks (el_from);
|
||||
CREATE INDEX el_to_domain_index_to_path ON /*_*/externallinks (el_to_domain_index, el_to_path);
|
||||
|
|
@ -426,22 +426,12 @@ CREATE INDEX pt_timestamp ON /*_*/protected_titles (pt_timestamp);
|
|||
CREATE TABLE /*_*/externallinks (
|
||||
el_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
el_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
|
||||
el_to BLOB DEFAULT '', el_index BLOB DEFAULT '',
|
||||
el_index_60 BLOB DEFAULT '' NOT NULL,
|
||||
el_to_domain_index BLOB DEFAULT '' NOT NULL,
|
||||
el_to_path BLOB DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX el_from ON /*_*/externallinks (el_from);
|
||||
|
||||
CREATE INDEX el_to ON /*_*/externallinks (el_to, el_from);
|
||||
|
||||
CREATE INDEX el_index ON /*_*/externallinks (el_index);
|
||||
|
||||
CREATE INDEX el_index_60 ON /*_*/externallinks (el_index_60, el_id);
|
||||
|
||||
CREATE INDEX el_from_index_60 ON /*_*/externallinks (el_from, el_index_60, el_id);
|
||||
|
||||
CREATE INDEX el_to_domain_index_to_path ON /*_*/externallinks (el_to_domain_index, el_to_path);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -391,21 +391,9 @@ CREATE TABLE /*_*/protected_titles (
|
|||
CREATE TABLE /*_*/externallinks (
|
||||
el_id INT UNSIGNED AUTO_INCREMENT NOT NULL,
|
||||
el_from INT UNSIGNED DEFAULT 0 NOT NULL,
|
||||
el_to BLOB DEFAULT NULL,
|
||||
el_index BLOB DEFAULT NULL,
|
||||
el_index_60 VARBINARY(60) DEFAULT '' NOT NULL,
|
||||
el_to_domain_index VARBINARY(255) DEFAULT '' NOT NULL,
|
||||
el_to_path BLOB DEFAULT NULL,
|
||||
INDEX el_from (el_from),
|
||||
INDEX el_to (
|
||||
el_to(60),
|
||||
el_from
|
||||
),
|
||||
INDEX el_index (
|
||||
el_index(60)
|
||||
),
|
||||
INDEX el_index_60 (el_index_60, el_id),
|
||||
INDEX el_from_index_60 (el_from, el_index_60, el_id),
|
||||
INDEX el_to_domain_index_to_path (
|
||||
el_to_domain_index,
|
||||
el_to_path(60)
|
||||
|
|
|
|||
|
|
@ -1302,24 +1302,6 @@
|
|||
"comment": "page_id of the referring page",
|
||||
"options": { "unsigned": true, "notnull": true, "default": 0 }
|
||||
},
|
||||
{
|
||||
"name": "el_to",
|
||||
"type": "blob",
|
||||
"comment": "The external link",
|
||||
"options": { "length": 65530, "notnull": false, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_index",
|
||||
"type": "blob",
|
||||
"comment": "In the case of HTTP URLs, this is the URL with any username or password removed, and with the labels in the hostname reversed and converted to lower case which will allow faster searching for all pages with WHERE clause. Note: If PHP's intl extension is enabled/disabled, maintenance/refreshExternallinksIndex.php needs to be run to refresh this field",
|
||||
"options": { "length": 65530, "notnull": false, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_index_60",
|
||||
"type": "binary",
|
||||
"comment": "'el_index' truncated to 60 bytes to allow for sortable queries that aren't supported by a partial index",
|
||||
"options": { "notnull": true, "length": 60, "default": "" }
|
||||
},
|
||||
{
|
||||
"name": "el_to_domain_index",
|
||||
"type": "binary",
|
||||
|
|
@ -1335,10 +1317,6 @@
|
|||
],
|
||||
"indexes": [
|
||||
{ "name": "el_from", "columns": [ "el_from" ], "unique": false },
|
||||
{ "name": "el_to", "columns": [ "el_to", "el_from" ], "unique": false, "options": { "lengths": [ 60, null ] } },
|
||||
{ "name": "el_index", "columns": [ "el_index" ], "unique": false, "options": { "lengths": [ 60 ] } },
|
||||
{ "name": "el_index_60", "columns": [ "el_index_60", "el_id" ], "unique": false },
|
||||
{ "name": "el_from_index_60", "columns": [ "el_from", "el_index_60", "el_id" ], "unique": false },
|
||||
{ "name": "el_to_domain_index_to_path", "columns": [ "el_to_domain_index", "el_to_path" ], "unique": false, "options": { "lengths": [ null, 60 ] } }
|
||||
],
|
||||
"pk": [ "el_id" ]
|
||||
|
|
|
|||
|
|
@ -195,11 +195,11 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
|
|||
$t,
|
||||
$po,
|
||||
'externallinks',
|
||||
[ 'el_to', 'el_index' ],
|
||||
[ 'el_to_domain_index', 'el_to_path' ],
|
||||
'el_from = ' . self::$testingPageId,
|
||||
[
|
||||
[ 'http://testing.com/wiki/Bar', 'http://com.testing./wiki/Bar' ],
|
||||
[ 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ],
|
||||
[ 'http://com.testing.', '/wiki/Bar' ],
|
||||
[ 'http://com.testing.', '/wiki/Foo' ],
|
||||
]
|
||||
);
|
||||
|
||||
|
|
@ -216,11 +216,11 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
|
|||
$t,
|
||||
$po,
|
||||
'externallinks',
|
||||
[ 'el_to', 'el_index' ],
|
||||
[ 'el_to_domain_index', 'el_to_path' ],
|
||||
'el_from = ' . self::$testingPageId,
|
||||
[
|
||||
[ 'http://testing.com/wiki/Bar', 'http://com.testing./wiki/Bar' ],
|
||||
[ 'http://testing.com/wiki/Baz', 'http://com.testing./wiki/Baz' ],
|
||||
[ 'http://com.testing.', '/wiki/Bar' ],
|
||||
[ 'http://com.testing.', '/wiki/Baz' ],
|
||||
]
|
||||
);
|
||||
|
||||
|
|
@ -862,7 +862,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
|
|||
/** @var ParserOutput $po */
|
||||
[ $t, $po ] = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
|
||||
$po->addCategory( $s, $s );
|
||||
$po->addExternalLink( $s );
|
||||
$po->addExternalLink( 'https://foo.com' );
|
||||
$po->addImage( $s );
|
||||
$po->addInterwikiLink( new TitleValue( 0, $s, '', $s ) );
|
||||
$po->addLanguageLink( "$s:$s" );
|
||||
|
|
|
|||
Loading…
Reference in a new issue