From 41ea588beff62d9f900a1950f105ae4cb474956e Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 9 Apr 2008 19:19:10 +0000 Subject: [PATCH] Improve query; add dupe and loop checking --- maintenance/populateParentId.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/maintenance/populateParentId.php b/maintenance/populateParentId.php index 66f30b8ca0..863d7edae6 100644 --- a/maintenance/populateParentId.php +++ b/maintenance/populateParentId.php @@ -39,10 +39,29 @@ function populate_rev_parent_id( $db ) { # the original previous revision of the title when the # edit was made... foreach( $res as $row ) { + # First, check rows with the same timestamp other than this one + # with a smaller rev ID. The highest ID "wins". This avoids loops + # as either id or timestamp need to be going from parent_id to parent_id $previousID = $db->selectField( 'revision', 'rev_id', - array( 'rev_page' => $row->rev_page, "rev_timestamp < '{$row->rev_timestamp}'" ), + array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $row->rev_timestamp, + "rev_id < {$row->rev_id}" ), __FUNCTION__, - array( 'ORDER BY' => 'rev_timestamp DESC' ) ); + array( 'ORDER BY' => 'rev_id DESC' ) ); + # If there are none, check the the highest ID with a lower timestamp + if( !$previousID ) { + # Get the highest older timestamp + $lastTimestamp = $db->selectField( 'revision', 'rev_timestamp', + array( 'rev_page' => $row->rev_page, "rev_timestamp < '{$row->rev_timestamp}'" ), + __FUNCTION__, + array( 'ORDER BY' => 'rev_timestamp DESC' ) ); + # If there is one, let the highest rev ID win + if( $lastTimestamp ) { + $previousID = $db->selectField( 'revision', 'rev_id', + array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $lastTimestamp ), + __FUNCTION__, + array( 'ORDER BY' => 'rev_id DESC' ) ); + } + } $previousID = intval($previousID); if( $previousID != $row->rev_parent_id ) $changed++; -- 2.20.1