mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-09-23 18:30:06 +00:00
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:
parent
9659f7283d
commit
5072e87c0b
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue