Skip to content

Go to a date years back with one read, and draw long drives the whole way - #109

Merged
blike merged 2 commits into
mainfrom
list-jump-to-date
Nov 10, 2026
Merged

blike merged 2 commits into
mainfrom
list-jump-to-date

Conversation

@blike

@blike blike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

On a long Tesla history, going to an old date on the Drives page lagged badly, the Charging calendar offered months back to 2016, and long drives' routes stopped short. This makes going to any date one page read, starts the Charging calendar at the first session, and draws every position of a drive.

Changes

  • Go to a date with one read. Picking a day the Drives or Charging list hasn't read yet used to read every page from today back to it. On a car with 9,365 drives, a day in 2022 took 47 pages and about 24 s of queries, with the list redrawing after each page, and every 5-minute refresh then re-read all 47. The list now opens at the picked record: one page, about 0.4 s.
  • Newer pages above. A list opened part way back has a "Show newer drives / Back to latest" row at the top, and the mobile picker's newer arrow reads the page above too. The list keeps its place as newer records arrive above. Listings take a new after parameter (both sources) for this.
  • Charging calendar starts at the first session. It had no start date, so it fell back to ten years back. The new GET /api/vehicles/:id/charging-coverage gives it one, as drive-coverage does for Drives.
  • Long drives draw the whole way (A drive's detail route stops short when the drive has more than 10,000 positions #108). Drive detail read only the first 10,000 positions, about an hour of streamed driving. On one database that was 113 of 12,137 drives, the longest 29,922 positions. Tesla and Rivian detail now read every position, and so do Tesla trips, which still simplify routes before sending. The map draws every point; the speed/elevation chart draws an even 1,000 (evenly(), CHART_POINTS).
  • Hovering the chart no longer redraws the page. The hovered point was held by the Drives page, so each new point redrew the drive card, calendar, every list row and the chart, and rebuilt the route. The map and chart now sit in their own RoutePanel; hovering moves only the map's marker, and the chart and route are built once per drive.
  • DOM component tests (The web package has no DOM test environment, so component behaviour cannot be tested #103). Adds jsdom and Testing Library. A test opts in with // @vitest-environment jsdom, so existing static tests are unchanged.

Testing

  • Unit tests added/updated: a jsdom test that goes to a date 900 days back and checks that two pages are read (not six), then Show newer and Back to latest; tests for evenly()
  • Integration tests passed: DB tests for after paging and charging coverage on both sources, plus every position of a 25,000-position Tesla drive (704/704 with TEST_DATABASE_URL)
  • Manually tested: against a real Tesla database (2 cars, 12,137 drives, 30M positions) in the browser, and by timing the server calls
  • Existing tests passed
On a real Tesla database Before After
Go to Sep 2022 on Drives 47 pages, ~24 s 1 page, ~0.4 s
Charging calendar's first month 2016 Sep 2022
Drive with 29,922 positions first 10,000 drawn all, in ~160 ms

Deployment

  • No special deployment requirements

… way

Going to a day the Drives or Charging list hadn't read yet read every
page from today back to it. On a TeslaMate car with 9,365 drives, a day
in 2022 took 47 pages and about 24 s of queries, the list redrawing a
growing pile of rows after each, and every refresh after that read all
47 again. Picking a day the list doesn't hold now opens the list there:
one page, about 0.4 s. Listings take `after` as well as `before`, so a
list opened part way back reads the newer pages above it, nearest
first, and keeps its place as they arrive; "Back to latest" goes
straight to the newest.

The Charging calendar offered every month back ten years, since nothing
said when charging history starts. A charging-coverage endpoint now
does, as drive coverage already did for Drives.

A drive's detail read its first 10,000 positions, so with streaming,
anything past about an hour drew a route that stopped short (113 of
12,137 drives on one database, the longest 29,922 positions). Both
sources now read every position, as do trips, which simplify the route
before sending it. The map draws them all; the speed and elevation
chart draws an even 2,000, as many as it can show.

The web package can now test components in a DOM: Testing Library and
jsdom, opted into per file, so the static tests are unchanged. The
first test goes to a date 900 days back and checks the list reads two
pages, not six.

Fixes #108
Fixes #103
The point hovered on the speed and elevation chart was held by the
Drives page itself, so each new point redrew the drive card, the
calendar, every row of the drive list, and the chart with new props,
and rebuilt the route from every position. Now the route map and chart
sit in a panel of their own that holds it: the chart is built once per
drive, and hovering moves only the marker on the map. The route is
built once per drive, too, and the chart draws an even 1,000 points
rather than 2,000, still more than one a pixel.
@blike
blike merged commit bf696ee into main Nov 10, 2026
1 check passed
@blike
blike deleted the list-jump-to-date branch November 10, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant