Charts: detect missing older cached prices in _firstUnavailablePrice (#3675)

* Charts: detect missing older cached prices in _firstUnavailablePrice

Only the newest cached point was checked, so after loading a short range
(e.g. 30D or 1H) a longer range (1Y/ALL or 1D) skipped the API fetch and
showed only the shorter range's data. Now walk the cached points aligned
to the requested precision from the range start and return the first
missing slot (before the oldest point, in a gap, or after the newest),
tolerating a single missing slot. The existing newest-point check is kept.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XHSNx4epaJ8hpwuFvWjTmy

* Charts: drop comment and logging, use explicit type in _firstUnavailablePrice

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XHSNx4epaJ8hpwuFvWjTmy

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
claude[bot]
2026-10-05 14:31:37 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 046e57c598
commit bd8cc6901e
+16
View File
@@ -122,6 +122,22 @@ class PriceStore {
return start;
}
prices.sort();
final precisionMs = precision.inMilliseconds;
DateTime expected = start;
for (final price in prices) {
if (price.time.millisecondsSinceEpoch % precisionMs != 0 || price.time.isBefore(start)) {
continue;
}
if (price.time.difference(expected) > precision) {
return expected;
}
expected = price.time.add(precision);
}
if (end.difference(expected) > precision) {
return expected;
}
final last = prices.last;
printV("last.time: ${last.time.toIso8601String()} end: ${end.toIso8601String()}");
if (last.time.isAfter(end.subtract(precision)) ||