Merge "RCFilters: Live update: no data returns 204"
[lhc/web/wiklou.git] / maintenance / populateIpChanges.php
index eb60f80..ffb8c43 100644 (file)
@@ -67,12 +67,12 @@ TEXT
                $this->output( "Copying IP revisions to ip_changes, from rev_id $start to rev_id $end\n" );
 
                while ( $blockStart <= $end ) {
-                       $cond = "rev_id >= $blockStart AND rev_user = 0 ORDER BY rev_id ASC LIMIT " . $this->mBatchSize;
                        $rows = $dbw->select(
                                'revision',
                                [ 'rev_id', 'rev_timestamp', 'rev_user_text' ],
-                               $cond,
-                               __METHOD__
+                               [ "rev_id >= $blockStart", 'rev_user' => 0 ],
+                               __METHOD__,
+                               [ 'ORDER BY' => 'rev_id ASC', 'LIMIT' => $this->mBatchSize ]
                        );
 
                        if ( !$rows || $rows->numRows() === 0 ) {
@@ -82,19 +82,15 @@ TEXT
                        $this->output( "...checking $this->mBatchSize revisions for IP edits that need copying, " .
                                "starting with rev_id $blockStart\n" );
 
+                       $insertRows = [];
                        foreach ( $rows as $row ) {
                                // Double-check to make sure this is an IP, e.g. not maintenance user or imported revision.
                                if ( IP::isValid( $row->rev_user_text ) ) {
-                                       $dbw->insert(
-                                               'ip_changes',
-                                               [
-                                                       'ipc_rev_id' => $row->rev_id,
-                                                       'ipc_rev_timestamp' => $row->rev_timestamp,
-                                                       'ipc_hex' => IP::toHex( $row->rev_user_text ),
-                                               ],
-                                               __METHOD__,
-                                               'IGNORE'
-                                       );
+                                       $insertRows[] = [
+                                               'ipc_rev_id' => $row->rev_id,
+                                               'ipc_rev_timestamp' => $row->rev_timestamp,
+                                               'ipc_hex' => IP::toHex( $row->rev_user_text ),
+                                       ];
 
                                        $revCount++;
                                }
@@ -104,6 +100,13 @@ TEXT
 
                        $blockStart++;
 
+                       $dbw->insert(
+                               'ip_changes',
+                               $insertRows,
+                               __METHOD__,
+                               'IGNORE'
+                       );
+
                        $lbFactory->waitForReplication();
                        usleep( $throttle * 1000 );
                }