From 9a6dd1307c90fd5a15dfe05510bb88e3af871d14 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Tue, 17 Sep 2019 12:31:49 +0200 Subject: [PATCH] Add new schemas for splitting afl_filter It'd be great if we could get this included in 1.34. Bug: T220791 Change-Id: I62d429d0eb6a7adc51cc37fe18f878077f85a006 --- abusefilter.tables.pg.sql | 21 +++++---- abusefilter.tables.sql | 5 ++- abusefilter.tables.sqlite.sql | 5 ++- db_patches/patch-split-afl_filter.sql | 7 +++ db_patches/patch-split-afl_filter.sqlite.sql | 47 ++++++++++++++++++++ includes/AbuseFilterHooks.php | 22 +++++++++ 6 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 db_patches/patch-split-afl_filter.sql create mode 100644 db_patches/patch-split-afl_filter.sqlite.sql diff --git a/abusefilter.tables.pg.sql b/abusefilter.tables.pg.sql index f9562472a..b2d5cad35 100644 --- a/abusefilter.tables.pg.sql +++ b/abusefilter.tables.pg.sql @@ -36,7 +36,7 @@ CREATE INDEX abuse_filter_action_consequence ON abuse_filter_action(afa_conseque CREATE SEQUENCE abuse_filter_log_afl_id_seq; CREATE TABLE abuse_filter_log ( afl_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('abuse_filter_log_afl_id_seq'), - afl_filter TEXT NOT NULL, + afl_filter TEXT NOT NULL DEFAULT '', afl_user INTEGER NOT NULL, afl_user_text TEXT NOT NULL, afl_ip TEXT NOT NULL, @@ -49,16 +49,19 @@ CREATE TABLE abuse_filter_log ( afl_wiki TEXT NULL, afl_deleted SMALLINT NOT NULL DEFAULT 0, afl_patrolled_by INTEGER NULL, - afl_rev_id INTEGER NULL + afl_rev_id INTEGER NULL, + afl_global SMALLINT NOT NULL DEFAULT 0, + afl_filter_id INTEGER NOT NULL DEFAULT 0 ); -CREATE INDEX abuse_filter_log_filter_timestamp ON abuse_filter_log(afl_filter,afl_timestamp); -CREATE INDEX abuse_filter_log_user_timestamp ON abuse_filter_log(afl_user,afl_user_text,afl_timestamp); -CREATE INDEX abuse_filter_log_timestamp ON abuse_filter_log(afl_timestamp); -CREATE INDEX abuse_filter_log_page_timestamp ON abuse_filter_log(afl_namespace, afl_title, afl_timestamp); -CREATE INDEX abuse_filter_log_ip_timestamp ON abuse_filter_log(afl_ip, afl_timestamp); -CREATE INDEX abuse_filter_log_rev_id ON abuse_filter_log(afl_rev_id); -CREATE INDEX abuse_filter_log_wiki_timestamp ON abuse_filter_log(afl_wiki, afl_timestamp); +CREATE INDEX abuse_filter_log_filter_timestamp ON abuse_filter_log(afl_filter,afl_timestamp); +CREATE INDEX abuse_filter_log_filter_timestamp_full ON abuse_filter_log(afl_global,afl_filter_id,afl_timestamp); +CREATE INDEX abuse_filter_log_user_timestamp ON abuse_filter_log(afl_user,afl_user_text,afl_timestamp); +CREATE INDEX abuse_filter_log_timestamp ON abuse_filter_log(afl_timestamp); +CREATE INDEX abuse_filter_log_page_timestamp ON abuse_filter_log(afl_namespace, afl_title, afl_timestamp); +CREATE INDEX abuse_filter_log_ip_timestamp ON abuse_filter_log(afl_ip, afl_timestamp); +CREATE INDEX abuse_filter_log_rev_id ON abuse_filter_log(afl_rev_id); +CREATE INDEX abuse_filter_log_wiki_timestamp ON abuse_filter_log(afl_wiki, afl_timestamp); CREATE SEQUENCE abuse_filter_history_afh_id_seq; CREATE TABLE abuse_filter_history ( diff --git a/abusefilter.tables.sql b/abusefilter.tables.sql index faedb1a31..a77095179 100644 --- a/abusefilter.tables.sql +++ b/abusefilter.tables.sql @@ -33,7 +33,9 @@ CREATE TABLE /*$wgDBprefix*/abuse_filter_action ( CREATE TABLE /*$wgDBprefix*/abuse_filter_log ( afl_id BIGINT unsigned NOT NULL AUTO_INCREMENT, - afl_filter varchar(64) binary NOT NULL, + afl_filter varchar(64) binary NOT NULL DEFAULT '', + afl_global tinyint(1) NOT NULL DEFAULT 0, + afl_filter_id BIGINT unsigned NOT NULL DEFAULT 0, afl_user BIGINT unsigned NOT NULL, afl_user_text varchar(255) binary NOT NULL, afl_ip varchar(255) not null, @@ -50,6 +52,7 @@ CREATE TABLE /*$wgDBprefix*/abuse_filter_log ( PRIMARY KEY (afl_id), KEY filter_timestamp (afl_filter,afl_timestamp), + KEY filter_timestamp_full (afl_global,afl_filter_id,afl_timestamp), KEY user_timestamp (afl_user,afl_user_text,afl_timestamp), KEY (afl_timestamp), KEY page_timestamp (afl_namespace, afl_title, afl_timestamp), diff --git a/abusefilter.tables.sqlite.sql b/abusefilter.tables.sqlite.sql index 170879aeb..812e318b4 100644 --- a/abusefilter.tables.sqlite.sql +++ b/abusefilter.tables.sqlite.sql @@ -31,7 +31,9 @@ CREATE INDEX afa_consequence ON /*$wgDBprefix*/abuse_filter_action (afa_conseque CREATE TABLE /*$wgDBprefix*/abuse_filter_log ( afl_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - afl_filter varbinary(64) NOT NULL, + afl_filter varbinary(64) NOT NULL DEFAULT '', + afl_global tinyint(1) NOT NULL DEFAULT 0, + afl_filter_id INTEGER NOT NULL DEFAULT 0, afl_user BIGINT unsigned NOT NULL, afl_user_text varbinary(255) NOT NULL, afl_ip varbinary(255) not null, @@ -47,6 +49,7 @@ CREATE TABLE /*$wgDBprefix*/abuse_filter_log ( afl_rev_id int unsigned ) /*$wgDBTableOptions*/; CREATE INDEX afl_filter_timestamp ON /*$wgDBprefix*/abuse_filter_log (afl_filter,afl_timestamp); +CREATE INDEX afl_filter_timestamp_full ON /*$wgDBprefix*/abuse_filter_log (afl_global,afl_filter_id,afl_timestamp); CREATE INDEX afl_user_timestamp ON /*$wgDBprefix*/abuse_filter_log (afl_user,afl_user_text,afl_timestamp); CREATE INDEX afl_timestamp ON /*$wgDBprefix*/abuse_filter_log (afl_timestamp); CREATE INDEX afl_page_timestamp ON /*$wgDBprefix*/abuse_filter_log (afl_namespace, afl_title, afl_timestamp); diff --git a/db_patches/patch-split-afl_filter.sql b/db_patches/patch-split-afl_filter.sql new file mode 100644 index 000000000..7b4652bd6 --- /dev/null +++ b/db_patches/patch-split-afl_filter.sql @@ -0,0 +1,7 @@ +-- Split afl_filter into afl_filter_id and afl_global +ALTER TABLE /*_*/abuse_filter_log + ADD COLUMN afl_global tinyint(1) NOT NULL DEFAULT 0 AFTER afl_filter, + ADD COLUMN afl_filter_id BIGINT unsigned NOT NULL DEFAULT 0 AFTER afl_global, + ALTER COLUMN afl_filter SET DEFAULT ''; + +CREATE INDEX /*i*/filter_timestamp_full ON /*_*/abuse_filter_log (afl_global,afl_filter_id,afl_timestamp); diff --git a/db_patches/patch-split-afl_filter.sqlite.sql b/db_patches/patch-split-afl_filter.sqlite.sql new file mode 100644 index 000000000..72894b6b5 --- /dev/null +++ b/db_patches/patch-split-afl_filter.sqlite.sql @@ -0,0 +1,47 @@ +-- Split afl_filter into afl_filter_id and afl_global +BEGIN; + +DROP TABLE IF EXISTS /*_*/abuse_filter_log_tmp; +CREATE TABLE /*_*/abuse_filter_log_tmp ( + afl_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + afl_filter varbinary(64) NOT NULL DEFAULT '', + afl_global tinyint(1) NOT NULL DEFAULT 0, + afl_filter_id INTEGER NOT NULL DEFAULT 0, + afl_user BIGINT unsigned NOT NULL, + afl_user_text varbinary(255) NOT NULL, + afl_ip varbinary(255) not null, + afl_action varbinary(255) not null, + afl_actions varbinary(255) not null, + afl_var_dump BLOB NOT NULL, + afl_timestamp varbinary(14) NOT NULL, + afl_namespace int NOT NULL, + afl_title varbinary(255) NOT NULL, + afl_wiki varbinary(64) NULL, + afl_deleted tinyint(1) NOT NULL DEFAULT 0, + afl_patrolled_by int unsigned NULL, + afl_rev_id int unsigned +) /*$wgDBTableOptions*/; + +INSERT OR IGNORE INTO /*_*/abuse_filter_log_tmp ( + afl_id, afl_filter, afl_user, afl_user_text, afl_ip, + afl_action, afl_actions, afl_var_dump, afl_timestamp, afl_namespace, afl_title, + afl_wiki, afl_deleted, afl_patrolled_by, afl_rev_id ) + SELECT + afl_id, afl_filter, afl_user, afl_user_text, afl_ip, + afl_action, afl_actions, afl_var_dump, afl_timestamp, afl_namespace, afl_title, + afl_wiki, afl_deleted, afl_patrolled_by, afl_rev_id + FROM /*_*/abuse_filter_log; + +DROP TABLE /*_*/abuse_filter_log; +ALTER TABLE /*_*/abuse_filter_log_tmp RENAME TO /*_*/abuse_filter_log; + +CREATE INDEX /*i*/afl_filter_timestamp ON /*_*/abuse_filter_log (afl_filter,afl_timestamp); +CREATE INDEX /*i*/afl_filter_timestamp_full ON /*_*/abuse_filter_log (afl_global,afl_filter_id,afl_timestamp); +CREATE INDEX /*i*/afl_user_timestamp ON /*_*/abuse_filter_log (afl_user,afl_user_text,afl_timestamp); +CREATE INDEX /*i*/afl_timestamp ON /*_*/abuse_filter_log (afl_timestamp); +CREATE INDEX /*i*/afl_page_timestamp ON /*_*/abuse_filter_log (afl_namespace, afl_title, afl_timestamp); +CREATE INDEX /*i*/afl_ip_timestamp ON /*_*/abuse_filter_log (afl_ip, afl_timestamp); +CREATE INDEX /*i*/afl_wiki_timestamp ON /*_*/abuse_filter_log (afl_wiki, afl_timestamp); +CREATE INDEX /*i*/afl_rev_id ON /*_*/abuse_filter_log (afl_rev_id); + +COMMIT; \ No newline at end of file diff --git a/includes/AbuseFilterHooks.php b/includes/AbuseFilterHooks.php index 860752e49..e40057bb9 100644 --- a/includes/AbuseFilterHooks.php +++ b/includes/AbuseFilterHooks.php @@ -661,6 +661,18 @@ class AbuseFilterHooks { $updater->addExtensionUpdate( [ 'dropField', 'abuse_filter_log', 'afl_log_id', "$dir/db_patches/patch-drop_afl_log_id.sqlite.sql", true ] ); } + + if ( $updater->getDB()->getType() == 'mysql' ) { + $updater->addExtensionUpdate( [ + 'addIndex', 'abuse_filter_log', 'filter_timestamp_full', + "$dir/db_patches/patch-split-afl_filter.sql", true + ] ); + } else { + $updater->addExtensionUpdate( [ + 'addIndex', 'abuse_filter_log', 'filter_timestamp_full', + "$dir/db_patches/patch-split-afl_filter.sqlite.sql", true + ] ); + } } elseif ( $updater->getDB()->getType() === 'postgres' ) { $updater->addExtensionUpdate( [ 'addTable', 'abuse_filter', "$dir/abusefilter.tables.pg.sql", true ] ); @@ -736,6 +748,16 @@ class AbuseFilterHooks { ] ); $updater->addExtensionUpdate( [ 'dropPgField', 'abuse_filter_log', 'afl_log_id' ] ); + $updater->addExtensionUpdate( [ + 'setDefault', 'abuse_filter_log', 'afl_filter', '' + ] ); + $updater->addExtensionUpdate( [ + 'addPgField', 'abuse_filter_log', 'afl_global', 'SMALLINT NOT NULL DEFAULT 0' ] ); + $updater->addExtensionUpdate( [ + 'addPgField', 'abuse_filter_log', 'afl_filter_id', 'INTEGER NOT NULL DEFAULT 0' ] ); + $updater->addExtensionUpdate( [ + 'addPgIndex', 'abuse_filter_log', 'abuse_filter_log_filter_timestamp_full', + '(afl_global, afl_filter_id, afl_timestamp)' ] ); } $updater->addExtensionUpdate( [ [ __CLASS__, 'createAbuseFilterUser' ] ] );