$estimate['blocker'] ? $estimate['blocker'] : 'nothing changed' ) ); return; } \AILSUG\Queue\Runs::start_paid( 'scan', null, (int) $estimate['fits'] ); } /** * Remember a changed post (cheap). * * @param int $post_id Post ID. * @param \WP_Post|null $post Post. * @return void */ public static function touch( $post_id, $post = null ) { if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { return; } $post = $post ? $post : get_post( $post_id ); if ( $post && ! in_array( $post->post_type, (array) Settings::get( 'post_types' ), true ) ) { return; } self::$touched[ (int) $post_id ] = (int) $post_id; } /** * Status transitions (publish ↔ draft/trash) change eligibility. * * @param string $new_status New. * @param string $old_status Old. * @param \WP_Post $post Post. * @return void */ public static function transition( $new_status, $old_status, $post ) { if ( $new_status !== $old_status && $post instanceof \WP_Post ) { self::touch( $post->ID, $post ); } } /** * At shutdown, enqueue one cheap local re-index job per touched post. * * @return void */ public static function flush() { if ( ! self::$touched ) { return; } $jobs = array(); foreach ( self::$touched as $id ) { $jobs[] = array( 'index', $id ); } self::$touched = array(); Queue::create_run( 'auto', $jobs ); Worker::schedule( 5 ); } }