@@ -77,8 +77,11 @@ export function useVirtualStreaming({
7777 const hasWarnedRef = useRef ( false ) ;
7878 const queryKeyString = JSON . stringify ( logsQueryKey ) ;
7979 const previousQueryKeyString = usePrevious ( queryKeyString ) ;
80+ const boxedVirtualTimestamp = useRef ( virtualTimestamp ) ;
81+ boxedVirtualTimestamp . current = virtualTimestamp ;
8082
8183 const organizationRef = useRef ( organization ) ;
84+ const autoRefreshMinuteCountRef = useRef ( 0 ) ;
8285
8386 useEffect ( ( ) => {
8487 if ( previousQueryKeyString !== queryKeyString ) {
@@ -129,28 +132,68 @@ export function useVirtualStreaming({
129132 return ;
130133 }
131134
132- if ( virtualTimestamp === undefined ) {
133- // First time enabling autorefresh, initialize virtual timestamp.
135+ if ( boxedVirtualTimestamp . current === undefined ) {
134136 initializeVirtualTimestamp ( ) ;
137+ logger . info ( 'Auto-refresh enabled: initializing virtual timestamp' , {
138+ organization : organization . slug ,
139+ reinitializedVirtualTimestamp : false ,
140+ autorefreshLog : true ,
141+ } ) ;
135142 return ;
136143 }
137144
138145 if ( isAutoRefreshContinued ) {
139- // Re-enabling autorefresh with existing virtual timestamp, and within continue window, do nothing.
146+ logger . info ( 'Auto-refresh enabled: continuing with existing virtual timestamp' , {
147+ organization : organization . slug ,
148+ reinitializedVirtualTimestamp : false ,
149+ virtualTimestamp : boxedVirtualTimestamp . current ,
150+ autorefreshLog : true ,
151+ } ) ;
140152 return ;
141153 }
142154 if ( ! isEqual ( autoRefresh , previousAutoRefresh ) ) {
143- // Re-enabling autorefresh with existing virtual timestamp, but outside continue window, reset virtual timestamp.
144155 initializeVirtualTimestamp ( ) ;
156+ logger . info ( 'Auto-refresh enabled: reinitializing virtual timestamp' , {
157+ organization : organization . slug ,
158+ reinitializedVirtualTimestamp : true ,
159+ previousVirtualTimestamp : boxedVirtualTimestamp . current ,
160+ autorefreshLog : true ,
161+ } ) ;
145162 }
146163 } , [
147164 autoRefresh ,
148165 initializeVirtualTimestamp ,
149- virtualTimestamp ,
166+ boxedVirtualTimestamp ,
150167 isAutoRefreshContinued ,
151168 previousAutoRefresh ,
169+ organization . slug ,
152170 ] ) ;
153171
172+ useEffect ( ( ) => {
173+ let intervalId : NodeJS . Timeout | undefined ;
174+
175+ autoRefreshMinuteCountRef . current = 0 ;
176+
177+ if ( autoRefresh ) {
178+ intervalId = setInterval ( ( ) => {
179+ autoRefreshMinuteCountRef . current += 1 ;
180+ logger . info ( 'Auto-refresh interval tick' , {
181+ organization : organization . slug ,
182+ minutesSinceEnabled : autoRefreshMinuteCountRef . current ,
183+ currentVirtualTimestamp : boxedVirtualTimestamp . current ,
184+ autorefreshLog : true ,
185+ } ) ;
186+ } , 60000 ) ;
187+ }
188+
189+ return ( ) => {
190+ if ( intervalId ) {
191+ clearInterval ( intervalId ) ;
192+ }
193+ autoRefreshMinuteCountRef . current = 0 ;
194+ } ;
195+ } , [ autoRefresh , organization . slug , boxedVirtualTimestamp ] ) ;
196+
154197 // Get the newest timestamp from the latest page to calculate how far behind we are
155198 const getMostRecentPageDataTimestamp = useCallback ( ( ) => {
156199 if ( ! data ?. pages ?. length ) {
0 commit comments