mirror of
https://github.com/rightup/pyMC_Repeater.git
synced 2026-05-09 06:54:28 +02:00
fdd788212d
Problem ------- rrdtool.fetch() is a blocking C library call that reads 24 hours of RRD data from disk. The dashboard can call get_data() on every page refresh. On an SD card each fetch can cost several milliseconds of I/O, and because the RRD step is 60 seconds the data cannot change more often than that — any fetch within the same 60-second window returns identical data. The combined-optimizations branch had a 60-second read cache; rightup's batching refactor inadvertently removed it. This PR restores it. Solution -------- * Add self._get_data_cache: tuple = (0.0, None) to __init__ * In get_data(): set use_cache = (start_time is None and end_time is None) - if use_cache and cache is < 60 s old: return cached result immediately - after a successful live fetch with use_cache: store (now, result) * Explicit start_time / end_time callers always bypass the cache so fine-grained or historical queries are never stale Why 60 s TTL? The RRD step is 60 s, so the database cannot hold a newer sample until the next step boundary. A 60-second cache is tight enough that the dashboard always shows data ≤ one step stale, and loose enough that a burst of refreshes costs one disk read instead of N. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>