prefix . $session_id ), 0, 40 ); if ( isset( self::$held[ $key ] ) ) { return $callback(); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Advisory locks require a live connection query; caching a lock result would break mutual exclusion. if ( '1' !== (string) $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, 0)', $key ) ) ) { throw new \RuntimeException( 'A request for this conversation is already running. Please retry shortly.' ); } self::$held[ $key ] = true; try { return $callback(); } finally { unset( self::$held[ $key ] ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Release the connection-owned lock immediately; this operation cannot be cached. $wpdb->get_var( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $key ) ); } } }