[2.x] Fix potential division by zero in CacheEventLog.toSummary (#8635)

Add guard to prevent division by zero when calculating hitRate.
If total is 0, hitRate is set to 0.0 instead of causing NaN or Infinity.
This commit is contained in:
dive2tech 2026-01-26 15:47:16 -05:00 committed by GitHub
parent 92b0564dc6
commit cf8899919d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 1 deletions

View File

@ -71,7 +71,7 @@ class CacheEventLog:
val hits = events.view.collect { case (ActionCacheEvent.Found(id), v) => (id, v) }.toMap
val hitCount = hits.values.sum
val missCount = total - hitCount
val hitRate = (hitCount.toDouble / total.toDouble)
val hitRate = if total > 0 then (hitCount.toDouble / total.toDouble) else 0.0
val onsiteCount = events.get(ActionCacheEvent.OnsiteTask)
val errorCount = events.get(ActionCacheEvent.Error)
CacheEventSummary.Data(