I am using django / apache / sqlite3, and I have a django model that looks like this:
class Temp_entry(models.Model):
dateTime = models.IntegerField()
sensor = models.IntegerField()
temp = models.IntegerField()
I am trying to get the last 300 Temp_entry elements to put them in a graph. I do like this:
revOutsideTempHistory = Temp_entry.objects.filter(sensor=49).order_by('dateTime').reverse()[:300]
However, this request takes ~ 1 second. Is there any way to improve this? I dug up and found that order_by is terribly inefficient, so I hope there is a viable alternative?
An alternative that I thought about, but I can’t figure out how to implement it, is to run the request every 20 minutes and save it in the cache, which will also be acceptable, as the data can be a little outdated without any side effects.
source
share