Skip to content

Commit 3fb6d2c

Browse files
committed
Expanded docs of the fake_boundary_datapoint logic
1 parent 8055261 commit 3fb6d2c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/cache/Cache.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ async function fetchSingleRange(
2525
significant_changes_only: boolean,
2626
minimal_response: boolean
2727
): Promise<HistoryInRange> {
28-
// We fetch slightly more than requested. The reason is the following:
28+
// We fetch slightly more than requested (i.e the range visible in the screen). The reason is the following:
2929
// When fetching data in a range `[startT,endT]`, Home Assistant adds a fictitious datapoint at
3030
// the start of the fetched period containing a copy of the first datapoint that occurred before
3131
// `startT`, except if there is actually one at `startT`.
32-
// We fetch slightly more than requested (`[startT-1,endT]`) and we mark the datapoint at
33-
// `startT-1` to be deleted (`fake_boundary_datapoint`). When merging the fetched data with the
34-
// cached one, we keep the fictitious datapoint only if it's placed at the start, otherwise it's
35-
// discarded. We don't really know whether the datapoint is fictitious or it's a real datapoint
36-
// that happened to be exactly at `startT-1`, therefore we purposely fetch it outside cached range
37-
// (which is `[startT,endT]`). Since it is not cached by our caching system, it will be requested
38-
// again in following fetches. If it's a real datapoint, it will be returned with new fetches,
39-
// otherwise it won't (which means that it was fictitious).
32+
// We fetch slightly more than requested/visible (`[startT-1,endT]`) and we mark the datapoint at
33+
// `startT-1` to be deleted (`fake_boundary_datapoint`). When merging the fetched data into the
34+
// cache, we keep the fictitious datapoint only if it's placed at the start (see `add` function), otherwise it's
35+
// discarded.
36+
// In general, we don't really know whether the datapoint is fictitious or it's a real datapoint
37+
// that happened to be exactly at `startT-1`, therefore we purposely fetch it outside the requested range
38+
// (which is `[startT,endT]`) and we leave it out of the "known cached ranges".
39+
// If it happens to be a a real datapoint, it will be fetched properly when the user scrolls/zooms bring it into
40+
// the visible part of the screen.
4041
//
4142
// Examples:
4243
//
@@ -47,7 +48,7 @@ async function fetchSingleRange(
4748
// _________ 1st fetch
4849
// * + +
4950
// ^
50-
// '-- point at the edge, kept
51+
// '-- point kept because it is out of the visible range
5152
//
5253
// _______ 2nd fetch
5354
// * + * + +

0 commit comments

Comments
 (0)