Closed nhoening closed 3 months ago
@Flix6x I just saw that most_recent_only
has been in use a while ago and is deprecated. Are you okay with resurrecting it? Or we use a slightly different name, like most_recent_single
.
@Flix6x I just saw that
most_recent_only
has been in use a while ago and is deprecated. Are you okay with resurrecting it? Or we use a slightly different name, likemost_recent_single
.
Is it still mentioned in the code? If so, can you provide a link. I don't see it.
I actually came across this place in FlexMeasures which still mentions it.
(I'm working on support of this new feature in FlexMeasures in parallel)
In timely-beliefs, it could be that it wasn't even ever used in the first place, having preferred more explicit names.
I'm fine with repurposing the argument in FlexMeasures, and introducing it in timely-beliefs.
Maybe testing this is best done with the supporting FlexMeasures PR? I can also imagine @victorgarcia98 taking this review up in your absence.
This PR adds a "ORDER_BY and LIMIT 1" strategy to
search_session()
, which drastically shortens the execution time for queries which really only want one (most recent) belief, e.g. to check connectivity status or show the latest measured value.In this PR; we add a search filter
most_recent_only
(notice the missing "s"). This addition retains backwards compatibility, so packages using timely beliefs should have an easy time starting to use them.Also, this PR adds an index to make sure the search time is constant, no matter how far in the past the most recent event might be. The index only adds fields used in the ORDER BY which is the recommended practice.
The psql session below demonstrates its effect in such a case (most recent event quite a while in the past - for sensors where the most recent even is really recent, execution time is fast anyway). I repeated each search twice to make sure we see a consistent behavior.
We also need to look into the space we are using with indices.