fix(2meet-data-optimizer): drop cached routed counts when the migration engine rebuilds post rows
- migrate_entity (drift-check --fix), migrate_group and migrate_group_batch write flat rows outside the Hook Bus: bump the routed count version (once per call / batch; not on dry runs; post rows only) - dev36: a vendor search kept counting 21515 of 21522 matches after a fix - Verify: composer test (704), test:integration (598), phpcs, stan - PR: PR-129
This commit is contained in:
@@ -26,6 +26,8 @@ class PostStatusSyncTest extends TestCase {
|
||||
'includes/engine/class-tmdo-hook-bus.php',
|
||||
'includes/engine/class-tmdo-post-status-sync.php',
|
||||
'includes/engine/class-tmdo-entity-migration-engine.php',
|
||||
'includes/integrations/class-tmdo-post-fields.php',
|
||||
'includes/query/class-tmdo-post-query-router.php',
|
||||
) as $file ) {
|
||||
require_once $base . $file;
|
||||
}
|
||||
@@ -223,6 +225,40 @@ class PostStatusSyncTest extends TestCase {
|
||||
$this->assertSame( array( 'pending', '2026-03-01 10:00:00' ), $this->copies( self::A )[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Backfills and drift-check --fix rebuild rows outside the Hook Bus: the
|
||||
* routed counts cached for the old rows must go (2.4 PR-129; dev36: a
|
||||
* vendor search kept counting 21515 of 21522 matches after a fix).
|
||||
*/
|
||||
public function test_rebuilding_post_rows_invalidates_cached_routed_counts(): void {
|
||||
global $wpdb;
|
||||
$status = $wpdb->prefix . TMDO_TABLE_PREFIX . 'migration_status';
|
||||
$wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->postmeta}` ( meta_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, post_id BIGINT UNSIGNED NOT NULL DEFAULT 0, meta_key VARCHAR(255) DEFAULT NULL, meta_value LONGTEXT, PRIMARY KEY (meta_id) ) ENGINE=InnoDB" );
|
||||
$wpdb->query( "CREATE TABLE IF NOT EXISTS `{$status}` ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, entity_type VARCHAR(50) NOT NULL, group_name VARCHAR(50) NOT NULL, last_id BIGINT UNSIGNED NOT NULL DEFAULT 0, total_migrated BIGINT UNSIGNED NOT NULL DEFAULT 0, status VARCHAR(20) NOT NULL DEFAULT 'pending', started_at DATETIME DEFAULT NULL, completed_at DATETIME DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY entity_group (entity_type, group_name) ) ENGINE=InnoDB" );
|
||||
$version = static fn() => $GLOBALS['_wp_last_changed'][ TMDO_Post_Query_Router::COUNT_VERSION_GROUP ] ?? null;
|
||||
try {
|
||||
$wpdb->query( "INSERT INTO `{$wpdb->postmeta}` (post_id, meta_key, meta_value) VALUES (2, 'k', 'a2-native')" );
|
||||
|
||||
$GLOBALS['_wp_last_changed'][ TMDO_Post_Query_Router::COUNT_VERSION_GROUP ] = 'before';
|
||||
TMDO_Entity_Migration_Engine::migrate_group( 'post', 'ps_a', array( 'resume' => false, 'sleep_ms' => 0, 'dry_run' => true ) );
|
||||
$this->assertSame( 'before', $version(), 'a dry run writes nothing' );
|
||||
|
||||
foreach ( array(
|
||||
'migrate_entity' => static fn() => TMDO_Entity_Migration_Engine::migrate_entity( 'post', 'ps_a', 2 ),
|
||||
'migrate_group' => static fn() => TMDO_Entity_Migration_Engine::migrate_group( 'post', 'ps_a', array( 'resume' => false, 'sleep_ms' => 0 ) ),
|
||||
'migrate_group_batch' => static fn() => TMDO_Entity_Migration_Engine::migrate_group_batch( 'post', 'ps_a' ),
|
||||
) as $path => $run ) {
|
||||
TMDO_Entity_Migration_Engine::reset_checkpoint( 'post', 'ps_a' );
|
||||
$GLOBALS['_wp_last_changed'][ TMDO_Post_Query_Router::COUNT_VERSION_GROUP ] = 'before';
|
||||
$run();
|
||||
$this->assertNotSame( 'before', $version(), $path );
|
||||
}
|
||||
} finally {
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->postmeta}`" );
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$status}`" );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_flat_write_that_creates_a_row_fills_the_copies(): void {
|
||||
TMDO_Post_Status_Sync::run();
|
||||
$mode = new ReflectionProperty( WPDO_Mode_Manager::class, 'cache' );
|
||||
|
||||
Reference in New Issue
Block a user