diff --git a/internal/dashboard/service.go b/internal/dashboard/service.go index b8b462c..2bdef2a 100644 --- a/internal/dashboard/service.go +++ b/internal/dashboard/service.go @@ -223,19 +223,13 @@ func (s *service) Statistics(ctx context.Context, query StatisticsQuery) (*Stati return redisCached, nil } - result, err := s.loadStatistics(ctx, days) - if err == nil { - return result, nil - } - - if redisCached, ok := s.getRedisStatistics(ctx, days); ok { - s.storeStatistics(days, redisCached) - return redisCached, nil - } - - s.logger.Error("Serving empty dashboard statistics after fetch failure", map[string]interface{}{ - "days": days, - "error": err.Error(), + // Cold cache: the underlying load performs a full MinIO bucket scan plus Mongo + // aggregations that can take minutes. Never block the request on it. Kick off a + // background refresh (deduped via singleflight) and serve an empty report so the + // endpoint stays fast; subsequent requests get full data once the cache warms. + go s.refreshStatistics(days) + s.logger.Info("Serving placeholder dashboard statistics while cache warms", map[string]interface{}{ + "days": days, }) return emptyStatisticsReport(days), nil }