Files
2meet-data-optimizer/tests/bench/seed.php
T
wpdev 8fc1dc1f1c test(2meet-data-optimizer): add scale seeder for 100k vendors / 1M listings
- Seed a HivePress-shaped dataset three ways (native meta, entity tables,
  hot table) with flat tables built by TMDO's own schema code
- Refuse any database not named *_bench before the bootstrap connects;
  bootstrap now honours a pre-defined ABSPATH for the wp-admin stub
- Full scale seeds 9.5M postmeta rows in 7m25s; 0 value mismatches

Verify: TMDO_TEST_DB_NAME=wp_wpdo_bench php tests/bench/seed.php
  --vendors=100000 --listings=1000000; unit 600 OK, integration 416 OK
PR: PR-004
2026-09-25 20:55:25 +08:00

52 lines
1.8 KiB
PHP

<?php
/**
* Seed the scale-benchmark dataset.
*
* Usage (DB credentials come from the same env vars as the integration suite):
* TMDO_TEST_DB_NAME=wp_wpdo_bench php tests/bench/seed.php --vendors=100000 --listings=1000000
*
* Options: --vendors=N (default 1000), --listings=N (default 10000), --seed=N (default 42),
* --batch=N rows per INSERT (default 2000).
*
* Drops and rebuilds its own wp_itest_* tables every run. Refuses any database
* whose name does not end in `_bench`.
*
* @package TMDO\Tests\Bench
*/
declare(strict_types=1);
if ( 'cli' !== PHP_SAPI ) {
exit( 1 );
}
require_once __DIR__ . '/class-tmdo-bench-seeder.php';
$opts = getopt( '', array( 'vendors::', 'listings::', 'seed::', 'batch::' ) );
$vendors = (int) ( $opts['vendors'] ?? 1000 );
$listings = (int) ( $opts['listings'] ?? 10000 );
$db_name = (string) getenv( 'TMDO_TEST_DB_NAME' );
try {
// Before the bootstrap: it runs CREATE DATABASE on whatever name it is given.
TMDO_Bench_Seeder::assert_bench_db( $db_name );
TMDO_Bench_Seeder::assert_count( 'vendors', $vendors );
TMDO_Bench_Seeder::assert_count( 'listings', $listings );
} catch ( InvalidArgumentException $e ) {
fwrite( STDERR, $e->getMessage() . PHP_EOL );
exit( 2 );
}
// Schema_Manager / Installer require ABSPATH . 'wp-admin/includes/upgrade.php'.
define( 'ABSPATH', __DIR__ . '/wp-stub/' );
require dirname( __DIR__ ) . '/integration/bootstrap.php';
$started = microtime( true );
$seeder = new TMDO_Bench_Seeder( $_mysqli, $wpdb->prefix, $vendors, $listings, (int) ( $opts['seed'] ?? 42 ), (int) ( $opts['batch'] ?? 2000 ) );
$counts = $seeder->run();
printf( "Seeded %s: %d vendors, %d listings in %.1fs\n", $db_name, $vendors, $listings, microtime( true ) - $started );
foreach ( $counts as $table => $rows ) {
printf( " %-40s %12d\n", $table, $rows );
}