Skip to content

Commit d325c75

Browse files
committed
handling potential race condition
1 parent a8634b4 commit d325c75

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

includes/Services/EventService.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,19 @@ private static function add_timestamp_and_ttl( $event ) {
110110
// Add timestamp and ttl to onboarding_complete event
111111
$event['data']['timestamp'] = $current_time;
112112

113-
// Calculate ttl from stored start time
113+
// Use the same completion time that was stored in handle_completed()
114+
$completion_time = get_option( Options::get_option_name( 'completed_time' ) );
114115
$start_time = get_option( Options::get_option_name( 'start_time' ) );
116+
115117
if ( $start_time ) {
116-
$ttl_seconds = $current_time - $start_time;
118+
if ( $completion_time ) {
119+
// Use stored completion time
120+
$ttl_seconds = $completion_time - $start_time;
121+
} else {
122+
// Fallback to current time if completion_time not found
123+
$ttl_seconds = $current_time - $start_time;
124+
}
125+
117126
if ( $ttl_seconds >= 0 ) {
118127
$event['data']['ttl'] = $ttl_seconds;
119128
}

0 commit comments

Comments
 (0)