1.4.1 (build 46): fix cambio de Chart Type roto por el cache de snapshots
El fetch del cache dependía del timeRange activo (monthsLimit = timeRange.months), así que al reutilizarlo entre chart types/rangos (optimización del build 45) los charts recibían historia truncada — Year vs Year o "All" con solo 12 meses, charts vacíos o incompletos al cambiar de tipo. Fix: el cache siempre guarda la historia completa (maxHistoryMonths) y el recorte por rango se hace en memoria (el filtro por cutoffDate ya existía justo después). Bonus: hiddenHistoryMonths ahora se calcula contra la ventana completa (teaser más preciso). Verificado en iPad Pro 13" simulador: Evolution 12M → All → Compare → Period vs Period → Evolution, todos renderizan con datos. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015qUZrBusG82T37R7PeokqJ
This commit is contained in:
@@ -448,17 +448,19 @@ class ChartsViewModel: ObservableObject {
|
||||
sources = sourceRepository.sources.filter { shouldIncludeSource($0) }
|
||||
}
|
||||
|
||||
let monthsLimit = timeRange.months ?? maxHistoryMonths
|
||||
let sourceIds = sources.compactMap { $0.id }
|
||||
|
||||
// Performance: Reuse cached snapshots when possible
|
||||
// Performance: cache the FULL history once and slice by time range in memory.
|
||||
// The cache is shared across chart types and ranges, so it must never be
|
||||
// fetched with a range-dependent months limit (that truncated Year vs Year
|
||||
// and "All" after visiting a chart with a shorter range).
|
||||
var snapshots: [Snapshot]
|
||||
if let cached = cachedSnapshots {
|
||||
snapshots = cached
|
||||
} else {
|
||||
snapshots = snapshotRepository.fetchSnapshots(
|
||||
for: sourceIds,
|
||||
months: monthsLimit
|
||||
months: maxHistoryMonths
|
||||
)
|
||||
hiddenHistoryMonths = freemiumValidator.hiddenHistoryMonths(in: snapshots)
|
||||
snapshots = freemiumValidator.filterSnapshots(snapshots)
|
||||
|
||||
Reference in New Issue
Block a user