From 4c08bf8d9613e8e0d94962d44d2e3ff32d1d70f8 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 15 Sep 2016 22:33:10 -0700 Subject: [PATCH] Avoid using cascadingDeletes()/cleanupTriggers() Simplify DB callers by just having one code path. All but some very old code paths bothered with these. Change-Id: Iaf7a2f83146a0ed15995f9cfc74edcf16ae5a448 --- includes/changes/RecentChange.php | 2 +- includes/deferred/LinksDeletionUpdate.php | 152 +++++++++++----------- includes/page/WikiPage.php | 5 +- maintenance/rebuildrecentchanges.php | 4 +- 4 files changed, 78 insertions(+), 85 deletions(-) diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 590fd3704f..306ea06e9f 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -312,7 +312,7 @@ class RecentChange { $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' ); # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL - if ( $dbw->cascadingDeletes() && $this->mAttribs['rc_cur_id'] == 0 ) { + if ( $this->mAttribs['rc_cur_id'] == 0 ) { unset( $this->mAttribs['rc_cur_id'] ); } diff --git a/includes/deferred/LinksDeletionUpdate.php b/includes/deferred/LinksDeletionUpdate.php index 41591665ed..93b3ef6526 100644 --- a/includes/deferred/LinksDeletionUpdate.php +++ b/includes/deferred/LinksDeletionUpdate.php @@ -108,87 +108,81 @@ class LinksDeletionUpdate extends DataUpdate implements EnqueueableDataUpdate { } } - // If using cascading deletes, we can skip some explicit deletes - if ( !$dbw->cascadingDeletes() ) { - // Delete outgoing links - $this->batchDeleteByPK( - 'pagelinks', - [ 'pl_from' => $id ], - [ 'pl_from', 'pl_namespace', 'pl_title' ], - $batchSize - ); - $this->batchDeleteByPK( - 'imagelinks', - [ 'il_from' => $id ], - [ 'il_from', 'il_to' ], - $batchSize - ); - $this->batchDeleteByPK( - 'categorylinks', - [ 'cl_from' => $id ], - [ 'cl_from', 'cl_to' ], - $batchSize - ); - $this->batchDeleteByPK( - 'templatelinks', - [ 'tl_from' => $id ], - [ 'tl_from', 'tl_namespace', 'tl_title' ], - $batchSize - ); - $this->batchDeleteByPK( - 'externallinks', - [ 'el_from' => $id ], - [ 'el_id' ], - $batchSize - ); - $this->batchDeleteByPK( - 'langlinks', - [ 'll_from' => $id ], - [ 'll_from', 'll_lang' ], - $batchSize - ); - $this->batchDeleteByPK( - 'iwlinks', - [ 'iwl_from' => $id ], - [ 'iwl_from', 'iwl_prefix', 'iwl_title' ], - $batchSize - ); - // Delete any redirect entry or page props entries - $dbw->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__ ); - $dbw->delete( 'page_props', [ 'pp_page' => $id ], __METHOD__ ); - } + $this->batchDeleteByPK( + 'pagelinks', + [ 'pl_from' => $id ], + [ 'pl_from', 'pl_namespace', 'pl_title' ], + $batchSize + ); + $this->batchDeleteByPK( + 'imagelinks', + [ 'il_from' => $id ], + [ 'il_from', 'il_to' ], + $batchSize + ); + $this->batchDeleteByPK( + 'categorylinks', + [ 'cl_from' => $id ], + [ 'cl_from', 'cl_to' ], + $batchSize + ); + $this->batchDeleteByPK( + 'templatelinks', + [ 'tl_from' => $id ], + [ 'tl_from', 'tl_namespace', 'tl_title' ], + $batchSize + ); + $this->batchDeleteByPK( + 'externallinks', + [ 'el_from' => $id ], + [ 'el_id' ], + $batchSize + ); + $this->batchDeleteByPK( + 'langlinks', + [ 'll_from' => $id ], + [ 'll_from', 'll_lang' ], + $batchSize + ); + $this->batchDeleteByPK( + 'iwlinks', + [ 'iwl_from' => $id ], + [ 'iwl_from', 'iwl_prefix', 'iwl_title' ], + $batchSize + ); - // If using cleanup triggers, we can skip some manual deletes - if ( !$dbw->cleanupTriggers() ) { - // Find recentchanges entries to clean up... - $rcIdsForTitle = $dbw->selectFieldValues( - 'recentchanges', - 'rc_id', - [ - 'rc_type != ' . RC_LOG, - 'rc_namespace' => $title->getNamespace(), - 'rc_title' => $title->getDBkey(), - 'rc_timestamp < ' . - $dbw->addQuotes( $dbw->timestamp( $this->timestamp ) ) - ], - __METHOD__ - ); - $rcIdsForPage = $dbw->selectFieldValues( - 'recentchanges', - 'rc_id', - [ 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ], - __METHOD__ - ); + // Delete any redirect entry or page props entries + $dbw->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__ ); + $dbw->delete( 'page_props', [ 'pp_page' => $id ], __METHOD__ ); + + // Find recentchanges entries to clean up... + $rcIdsForTitle = $dbw->selectFieldValues( + 'recentchanges', + 'rc_id', + [ + 'rc_type != ' . RC_LOG, + 'rc_namespace' => $title->getNamespace(), + 'rc_title' => $title->getDBkey(), + 'rc_timestamp < ' . + $dbw->addQuotes( $dbw->timestamp( $this->timestamp ) ) + ], + __METHOD__ + ); + $rcIdsForPage = $dbw->selectFieldValues( + 'recentchanges', + 'rc_id', + [ 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ], + __METHOD__ + ); - // T98706: delete by PK to avoid lock contention with RC delete log insertions - $rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize ); - foreach ( $rcIdBatches as $rcIdBatch ) { - $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ ); - if ( count( $rcIdBatches ) > 1 ) { - $lbFactory->commitAndWaitForReplication( - __METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ] - ); - } + // T98706: delete by PK to avoid lock contention with RC delete log insertions + $rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize ); + foreach ( $rcIdBatches as $rcIdBatch ) { + $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ ); + if ( count( $rcIdBatches ) > 1 ) { + $lbFactory->commitAndWaitForReplication( + __METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ] + ); } } diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index faac26dc06..2308ef0a31 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -3017,10 +3017,7 @@ class WikiPage implements Page, IDBAccessObject { // Now that it's safely backed up, delete it $dbw->delete( 'page', [ 'page_id' => $id ], __METHOD__ ); - - if ( !$dbw->cascadingDeletes() ) { - $dbw->delete( 'revision', [ 'rev_page' => $id ], __METHOD__ ); - } + $dbw->delete( 'revision', [ 'rev_page' => $id ], __METHOD__ ); // Log the deletion, if the page was suppressed, put it in the suppression log instead $logtype = $suppress ? 'suppress' : 'delete'; diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php index 6465bb32fa..458dacf56d 100644 --- a/maintenance/rebuildrecentchanges.php +++ b/maintenance/rebuildrecentchanges.php @@ -304,6 +304,8 @@ class RebuildRecentchanges extends Maintenance { ] ); + $field = $dbw->fieldInfo( 'recentchanges', 'rc_cur_id' ); + $inserted = 0; foreach ( $res as $row ) { $dbw->insert( @@ -323,7 +325,7 @@ class RebuildRecentchanges extends Maintenance { 'rc_last_oldid' => 0, 'rc_type' => RC_LOG, 'rc_source' => $dbw->addQuotes( RecentChange::SRC_LOG ), - 'rc_cur_id' => $dbw->cascadingDeletes() + 'rc_cur_id' => $field->isNullable() ? $row->page_id : (int)$row->page_id, // NULL => 0, 'rc_log_type' => $row->log_type, -- 2.20.1