gchenuet / nest-datagraph

Nest thermostat dashboard and graph charts
MIT License
36 stars 17 forks source link

date function used repeatedly which increases load time #35

Closed fusenuk closed 3 years ago

fusenuk commented 5 years ago

In the PHP code to pull the data from the SQL db you use code like

https://github.com/gchenuet/nest-datagraph/blob/master/frontend/php/getTemp.php#L14

$date_array = "Date(".date('Y', $phpdate).",".(date('n', $phpdate)-1).",".date('d', $phpdate).",".date('H', $phpdate).",".date('i', $phpdate).")";

which I just found out almost doubles the page load time when running this script on an old Raspberry Pi.

Changing the code to be

$nMinus = date('n', $phpdate)-1;
$date_array = "Date(".date('Y,'.$nMinus.',d,H,i', $phpdate).")";

helps massively. it brought the total loading of JSON data for the energy.php page down from 11 seconds to 6 seconds.

gchenuet commented 5 years ago

Thanks for this issues. Could you please open a PR to fix it ? Thanks!