@@ -101,7 +101,7 @@ func (p *NotificationService) SetContext(ctx basecontext.ApiContext) *Notificati
101101
102102func (p * NotificationService ) ResetCounters (correlationId string ) {
103103 if correlationId != "" {
104- delete (p .progressCounters , correlationId )
104+ delete (p .progressCounters , normalizeCorrelationID ( correlationId ) )
105105 }
106106}
107107
@@ -172,10 +172,11 @@ func (p *NotificationService) updateProgressTracker(tracker *ProgressTracker, pr
172172
173173func (p * NotificationService ) NotifyProgress (correlationId string , prefix string , progress float64 ) {
174174 msg := NewProgressNotificationMessage (correlationId , prefix , progress )
175+ encodedID := msg .CorrelationId ()
175176
176177 // Create or update progress tracker
177178 p .mu .Lock ()
178- tracker , exists := p .activeProgress [correlationId ]
179+ tracker , exists := p .activeProgress [encodedID ]
179180 if ! exists {
180181 tracker = & ProgressTracker {
181182 StartTime : time .Now (),
@@ -184,23 +185,28 @@ func (p *NotificationService) NotifyProgress(correlationId string, prefix string
184185 RateSamples : make ([]RateSample , 0 , 60 ),
185186 TotalSize : msg .totalSize , // Make sure we capture the total size
186187 }
187- p .activeProgress [correlationId ] = tracker
188+ p .activeProgress [encodedID ] = tracker
188189 }
189- p .mu .Unlock ()
190190
191- p .updateProgressTracker (tracker , progress , msg .currentSize )
191+ currentSize := msg .currentSize
192+ if currentSize == 0 {
193+ currentSize = tracker .CurrentSize
194+ }
195+ p .updateProgressTracker (tracker , progress , currentSize )
192196
193197 if progress >= 100 {
194198 msg .Close ()
195199 tracker .IsComplete = true
196200 }
201+ p .mu .Unlock ()
197202
198203 p .Notify (msg )
199204}
200205
201206func (p * NotificationService ) FinishProgress (correlationId string , prefix string ) {
207+ encodedID := normalizeCorrelationID (correlationId )
202208 p .mu .Lock ()
203- if tracker , exists := p .activeProgress [correlationId ]; exists {
209+ if tracker , exists := p .activeProgress [encodedID ]; exists {
204210 tracker .CurrentProgress = 100
205211 tracker .LastUpdateTime = time .Now ()
206212 tracker .IsComplete = true
@@ -353,22 +359,30 @@ func (p *NotificationService) CleanupNotifications(correlationId string) {
353359 return
354360 }
355361
362+ encodedID := normalizeCorrelationID (correlationId )
363+ p .cleanupNotificationsByEncodedID (encodedID )
364+ p .ctx .LogDebugf ("Cleaned up notifications for correlation ID: %s" , correlationId )
365+ }
366+
367+ func (p * NotificationService ) cleanupNotificationsByEncodedID (encodedID string ) {
368+ if encodedID == "" {
369+ return
370+ }
371+
356372 // Remove from active progress tracking
357373 p .mu .Lock ()
358- delete (p .activeProgress , correlationId )
374+ delete (p .activeProgress , encodedID )
359375 p .mu .Unlock ()
360376
361377 // Reset previous message if it was for this correlation ID
362- if p .previousMessage .correlationId == correlationId {
378+ if p .previousMessage .correlationId == encodedID {
363379 p .previousMessage = NotificationMessage {}
364380 }
365381
366382 // Reset current message if it was for this correlation ID
367- if p .CurrentMessage .correlationId == correlationId {
383+ if p .CurrentMessage .correlationId == encodedID {
368384 p .CurrentMessage = NotificationMessage {}
369385 }
370-
371- p .ctx .LogDebugf ("Cleaned up notifications for correlation ID: %s" , correlationId )
372386}
373387
374388// GetActiveProgressCount returns the number of active progress notifications
@@ -391,18 +405,20 @@ func (p *NotificationService) GetActiveProgressIDs() []string {
391405
392406// IsProgressActive checks if a progress notification is active for the given correlation ID
393407func (p * NotificationService ) IsProgressActive (correlationId string ) bool {
408+ encodedID := normalizeCorrelationID (correlationId )
394409 p .mu .RLock ()
395410 defer p .mu .RUnlock ()
396- _ , exists := p .activeProgress [correlationId ]
411+ _ , exists := p .activeProgress [encodedID ]
397412 return exists
398413}
399414
400415// GetProgressStatus returns the current progress status for a given correlation ID
401416// Returns progress percentage and whether the progress exists
402417func (p * NotificationService ) GetProgressStatus (correlationId string ) (float64 , bool ) {
418+ encodedID := normalizeCorrelationID (correlationId )
403419 p .mu .RLock ()
404420 defer p .mu .RUnlock ()
405- if tracker , exists := p .activeProgress [correlationId ]; exists {
421+ if tracker , exists := p .activeProgress [encodedID ]; exists {
406422 return tracker .CurrentProgress , true
407423 }
408424 return 0 , false
@@ -425,26 +441,32 @@ func (p *NotificationService) CleanupStaleProgress(staleDuration time.Duration)
425441
426442 // Then cleanup each ID (this will acquire write lock)
427443 for _ , id := range idsToCleanup {
428- p .ctx .LogDebugf ("Cleaning up stale progress for correlation ID: %s" , id )
429- p .CleanupNotifications (id )
444+ decodedID , err := decodeCorrelationID (id )
445+ if err != nil || decodedID == "" {
446+ decodedID = id
447+ }
448+ p .ctx .LogDebugf ("Cleaning up stale progress for correlation ID: %s" , decodedID )
449+ p .cleanupNotificationsByEncodedID (id )
430450 }
431451}
432452
433453// GetProgressDuration returns the duration since the progress started
434454func (p * NotificationService ) GetProgressDuration (correlationId string ) (time.Duration , bool ) {
455+ encodedID := normalizeCorrelationID (correlationId )
435456 p .mu .RLock ()
436457 defer p .mu .RUnlock ()
437- if tracker , exists := p .activeProgress [correlationId ]; exists {
458+ if tracker , exists := p .activeProgress [encodedID ]; exists {
438459 return time .Since (tracker .StartTime ), true
439460 }
440461 return 0 , false
441462}
442463
443464// GetProgressRate calculates transfer and progress rates for a given correlation ID
444465func (p * NotificationService ) GetProgressRate (correlationId string ) (* ProgressRate , bool ) {
466+ encodedID := normalizeCorrelationID (correlationId )
445467 p .mu .RLock ()
446468 defer p .mu .RUnlock ()
447- tracker , exists := p .activeProgress [correlationId ]
469+ tracker , exists := p .activeProgress [encodedID ]
448470 if ! exists || tracker .TotalSize <= 0 {
449471 return nil , false
450472 }
@@ -465,9 +487,10 @@ func (p *NotificationService) GetProgressRate(correlationId string) (*ProgressRa
465487
466488// PredictTimeRemaining estimates the time remaining based on recent progress
467489func (p * NotificationService ) PredictTimeRemaining (correlationId string ) (time.Duration , bool ) {
490+ encodedID := normalizeCorrelationID (correlationId )
468491 p .mu .RLock ()
469492 defer p .mu .RUnlock ()
470- tracker , exists := p .activeProgress [correlationId ]
493+ tracker , exists := p .activeProgress [encodedID ]
471494 if ! exists || tracker .TotalSize <= 0 {
472495 return 0 , false
473496 }
0 commit comments