teslamate-org / teslamate

A self-hosted data logger for your Tesla 🚘
https://docs.teslamate.org
MIT License
6.05k stars 755 forks source link

perf: exclude streaming data when getting battery level #4286

Closed swiffer closed 1 month ago

swiffer commented 1 month ago

another performance fix - query detected to be "slow" / having high mean_exec_time via pg_stat_statements.

in difference to other queries the "Battery Level" in "Overview" dashboard is not filtering positions based on selected time range causing a filter over positions_date_index.

adding the condition ideal_battery_range_km is not null is ok here, reduces rows to scan drastically.

could be further optimized (not neccessary) if adding time range filter to positions subquery, however the value would be empty then if no data recorded in last 24 hours.

i wonder if positions_car_id_index and positions_date_index provide the best value as positions data is filtered by car & date in most cases and indexes cannot be combined. it might be benefitical to change those indexes similary to the change of the positions_drive_id_index in https://github.com/teslamate-org/teslamate/pull/3186

netlify[bot] commented 1 month ago

Deploy Preview for teslamate ready!

Name Link
Latest commit a6994a315290482f1a13bc9155a096885b605c5f
Latest deploy log https://app.netlify.com/sites/teslamate/deploys/6714b5690f4d8b0008d925b2
Deploy Preview https://deploy-preview-4286--teslamate.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.