vitalidze / traccar-web

Traccar Web UI mod
http://traccar.litvak.su/
151 stars 145 forks source link

Last but not latest #97

Open Abyss777 opened 9 years ago

Abyss777 commented 9 years ago

I've faced with situation then last record in database is not latest.

Here https://github.com/tananaev/traccar/issues/1099 my tracker sent some coordinates from the past.The situation is weired. But web interface had shown tracker position from the past, until my tracker sent new actual coordinates.( If it's not moving it send it every 45 minutes)

After that I've analized my database and got a lot of cases then positions in database not ordered by the time. I think it happend because of bad GPRS connection or other circumstances. Or if i reboot tracker it will sent time from 2006-08-10 06:00:00 until fix GPS coordinates.

Anyway web interface should show latest position, but not last. (At least during the first start)

SQL something like this select * from POSITIONS where TIME = (select MAX(TIME) from POSITIONS) AND DEVICE_ID = 1

vitalidze commented 9 years ago

Such approach scales badly (i.e. when number of position grows time used to make such query will increase). I think it's better to update latest position correctly on backend side, it may check the time of position before updating that field in device. Maybe this can even be done in SQL query (using IF clause or so), which is configurable for backend.