backfillReadBundles.php: Use sub-select to target rows to update

UPDATE based on (user,display_hash) index

Bug: T136368
Change-Id: If3348c2e663517b632c9ff3194dd4a197c74159b
This commit is contained in:
Stephane Bisson 2016-06-07 09:22:43 -04:00 committed by Catrope
parent 9659f7283d
commit 5072e87c0b

View file

@ -16,24 +16,37 @@ class BackfillReadBundles extends Maintenance {
}
public function execute() {
$dbw = MWEchoDbFactory::getDB( DB_MASTER );
$dbr = MWEchoDbFactory::getDB( DB_SLAVE );
$dbFactory = MWEchoDbFactory::newFromDefault();
$dbw = $dbFactory->getEchoDb( DB_MASTER );
$dbr = $dbFactory->getEchoDb( DB_SLAVE );
$iterator = new BatchRowIterator(
$dbr,
'echo_notification',
array( 'notification_event', 'notification_user' ),
array( 'notification_user', 'notification_event' ),
$this->mBatchSize
);
$iterator->setFetchColumns( array( 'notification_bundle_display_hash', 'notification_read_timestamp' ) );
$unreadNonBase = $dbr->selectSQLText(
'echo_notification',
'notification_bundle_display_hash',
array(
'notification_bundle_base' => 0,
'notification_read_timestamp IS NULL',
"notification_bundle_display_hash <> ''",
)
);
$iterator->addConditions( array(
'notification_bundle_base' => 1,
"notification_bundle_display_hash <>'' ",
'notification_read_timestamp IS NOT NULL',
"notification_bundle_display_hash IN ( $unreadNonBase )",
) );
$processed = 0;
foreach ( $iterator as $batch ) {
foreach ( $batch as $row ) {
$userId = $row->notification_user;
$displayHash = $row->notification_bundle_display_hash;
$readTimestamp = $row->notification_read_timestamp;
@ -41,9 +54,10 @@ class BackfillReadBundles extends Maintenance {
'echo_notification',
array( 'notification_read_timestamp' => $readTimestamp ),
array(
'notification_read_timestamp IS NULL',
'notification_bundle_base' => 0,
'notification_user' => $userId,
'notification_bundle_display_hash' => $displayHash,
'notification_bundle_base' => 0,
'notification_read_timestamp IS NULL',
)
);
@ -55,6 +69,7 @@ class BackfillReadBundles extends Maintenance {
}
$this->output( "Updated $processed notifications.\n" );
$dbFactory->waitForSlaves();
}
}
}