Automattic\WooCommerce\Internal\PushNotifications\DataStores
PushTokensDataStore::flush_last_sent_at
Writes the buffered last-send stamps.
Runs on shutdown and after each Action Scheduler action, and is safe to call directly to force the write early.
Failure is swallowed: not knowing when a token was last used is a diagnostic gap, and must never turn a delivered notification into a failed one.
Method of the class: PushTokensDataStore{}
No Hooks.
Returns
void. Nothing (null).
Usage
$PushTokensDataStore = new PushTokensDataStore(); $PushTokensDataStore->flush_last_sent_at(): void;
Changelog
| Since 11.2.0 | Introduced. |
PushTokensDataStore::flush_last_sent_at() PushTokensDataStore::flush last sent at code WC 11.3.0
public function flush_last_sent_at(): void {
// Lets a later `record_last_sent_at()` re-assert the Action Scheduler
// hook, which fires once per action. It cannot re-arm `shutdown`:
// WP_Hook iterates a copy of its callbacks, so a stamp recorded during
// shutdown after this ran is dropped. No path does that today.
$this->last_sent_at_flush_registered = false;
if ( empty( $this->pending_last_sent_at ) ) {
return;
}
$pending = $this->pending_last_sent_at;
$this->pending_last_sent_at = array();
// Chunked so neither the `IN` list nor the number of placeholders handed
// to `$wpdb->prepare()` grows with the number of registered devices. A
// large `IN` list can also push the optimizer off the `post_id` index.
foreach ( array_chunk( $pending, self::LAST_SENT_AT_CHUNK_SIZE, true ) as $chunk ) {
try {
$this->write_last_sent_at_chunk( $chunk );
} catch ( Throwable $e ) {
// Throwable, not Exception. `action_scheduler_after_execute`
// fires between the action running and `mark_complete()`, inside
// the runner's own Throwable catch, so an Error escaping here
// would record a delivered notification's action as failed.
$this->warn_last_sent_at_not_recorded( array_keys( $chunk ), $e->getMessage() );
}
}
}