feat(2meet-data-optimizer): store post_status and post_date copies in post entity tables

- TMDO_Post_Status_Sync: post group tables get post_status / post_date
  columns (posts' collation) and an (post_status, post_date) index.
  Brand-new empty tables get them on creation; existing tables only via
  `wp tmdo post-status-sync [--dry-run] [--batch]`, never as DDL on a
  populated table in a web request. Per-group state in
  tmdo_post_status_columns ('columns' | 'ready').
- transition_post_status refreshes the copies; Hook Bus upserts that
  create a post row fill them in (existing rows keep theirs).
- Bench (1M rows): add columns 0.05 s, index 5.3 s, batched backfill 32 s,
  0 mismatches afterwards.
- Verify: core unit 659 / integration 466 green, phpcs clean
- PR: PR-028
This commit is contained in:
2026-09-26 01:25:20 +08:00
parent f4eee2338b
commit aeca12b41d
9 changed files with 471 additions and 4 deletions
+45
View File
@@ -303,6 +303,50 @@ class TMDO_CLI_Post {
WP_CLI::success( 'Post groups reconciled; tmdo_post_scoped_routing is on.' );
}
// ── post-status-sync ──────────────────────────────────────────────────────
/**
* Add post_status / post_date copies (and their index) to every post
* group table and fill them from wp_posts.
*
* Existing tables only get the columns here, never in a web request:
* ALTER on a large table can take seconds. Afterwards status changes keep
* the copies current. Re-run after bulk writes that bypass WordPress
* (e.g. post-reconcile-groups, post migrations).
*
* ## OPTIONS
*
* [--dry-run]
* : Count rows whose copies are missing or stale; change nothing.
*
* [--batch=<n>]
* : Rows per UPDATE. Default 1000.
*
* ## EXAMPLES
*
* wp tmdo post-status-sync --dry-run
* wp tmdo post-status-sync
*
* @param array $args Positional arguments (unused).
* @param array $assoc_args Named arguments.
*/
public function post_status_sync( $args, $assoc_args ): void {
$dry_run = isset( $assoc_args['dry-run'] );
$report = TMDO_Post_Status_Sync::run( $dry_run, (int) ( $assoc_args['batch'] ?? 1000 ) );
if ( empty( $report ) ) {
WP_CLI::log( 'No post group tables.' );
}
foreach ( $report as $group => $r ) {
WP_CLI::log( sprintf( '%s: %d row(s), %d missing or stale%s', $group, $r['rows'], $r['mismatched'], $dry_run ? '' : sprintf( ' → %s', TMDO_Post_Status_Sync::state( $group ) ) ) );
}
if ( $dry_run ) {
WP_CLI::success( '[dry-run] Nothing changed.' );
return;
}
WP_CLI::success( 'post_status / post_date copies are in sync.' );
}
// ── post-cleanup (v2.9.3) ─────────────────────────────────────────────────
/**
@@ -883,3 +927,4 @@ WP_CLI::add_command( 'wpdo post-shadow-report', array( 'TMDO_CLI_Post', 'post_sh
WP_CLI::add_command( 'tmdo post-shadow-report', array( 'TMDO_CLI_Post', 'post_shadow_report' ) );
WP_CLI::add_command( 'wpdo post-reconcile-groups', array( 'TMDO_CLI_Post', 'post_reconcile_groups' ) );
WP_CLI::add_command( 'tmdo post-reconcile-groups', array( 'TMDO_CLI_Post', 'post_reconcile_groups' ) );
WP_CLI::add_command( 'tmdo post-status-sync', array( 'TMDO_CLI_Post', 'post_status_sync' ) );