Closed Techn1x closed 2 years ago
@Techn1x I like this. Definitely agree with the general idea just unsure about the implementation right now. Perhaps we can look to other projects tackling this for inspiration on how they "back off" on counting within certain windows of time.
When we add it, it would be good if we somehow make the backoff logic/values easy to override - that way if the way we implement it isn't perfect, the code can still be used by most but tweaked as needed.
@Techn1x I like that idea... allow a strategy to be passed in as a prop or defined somewhere in the app (service?).
Had another quick think about this... the best, most accurate backoff strategy that would probably work for everyone would be if we somehow had a list of the defined intervals that fromNow uses, and adjust the update interval to always be when the next change is due to occur
Assuming the following 'fromNow' intervals;
a few seconds ago ( when 0 < time < 60s)
a minute ago (when 60s < time < 2min)
2 minutes ago (etc...)
3 minutes ago
4 minutes ago
...
1 hour ago
2 hours ago
3 hours ago
...
1 day ago
2 days ago
...
etc.
If a time was received that was 3 minutes 12 seconds ago, the next fromNow interval is at the '4 minutes ago' mark, so the next update interval to use should be set to exactly (4 minutes - 3min12sec) == 48 seconds. Once that is reached, the helper is recomputed and the new update interval would be calculated as 5 minutes - 4 minutes == 60 seconds
So the algorithm would be something like nextfromnowinterval - receivedTime = next update interval to use
Following this approach the moment-from-now would only ever update at the exact moment it needs to change
This will help to retrieve the existing humanized intervals https://github.com/moment/momentjs.com/blob/master/docs/moment/07-customization/13-relative-time-threshold.md
I've been using the
moment-from-now
helper a lot, and on one of my pages I use it many times with varying times supplied, like so;This is useful because they will display
a few seconds ago
then change value accordingly as the supplied times get older. However, once the times get older, it's far less critical to have the interval so precise (for example, if a time is5 days ago
there is no need to update it every second, and having many of these on the same page is a bit of a drag on performance)For this reason, I implemented the following helper in my app
This was my quick and dirty approach, but would it be best if this logic were built into the
moment-from-now
helper in ember-moment, with something likeinterval=auto
? Or is this something that should be implemented on a case-by-case basis like I have done