-
Notifications
You must be signed in to change notification settings - Fork 781
Reappearing notifications on slow homeservers #4238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reappearing notifications on slow homeservers #4238
Conversation
…es causing already dismissed notifications from being shown again - uses a simple circular buffer to limit the memory usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one small remark and one suggestion that you must feel free to just ignore :)
cache[writeIndex] = key | ||
writeIndex++ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking of a small rework, also more generic, but with the disadvantage of exposing the whole MutableList API...
/**
* A FIFO circular buffer of elements
*/
class CircularCache<T>(cacheSize: Int) : MutableList<T> by ArrayList(cacheSize) {
private var writeIndex = 0
override fun add(element: T): Boolean {
if (writeIndex == size - 1) {
writeIndex = 0
}
set(writeIndex, element)
writeIndex++
return true
}
}
You decide if it's better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set(writeIndex, element)
may crash (not tested)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe add as a comment that this is not thread safe (I think)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
👍 for switching to a List, I originally chose
Array
to try and be as memory efficient as possible (asList
will auto resize when it gets close to the capacity) butList
allows it to be generic -
I'd prefer to avoid exposing the
List
to avoid it being used in unexpected ways -
👍 will document the class as not being thread safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ended up going back to using an Array, a list means we have to handle prefilling or add/remove logic
// we've already seen the event, lets' skip | ||
Timber.d("onNotifiableEventReceived(): skipping event, already seen}") | ||
} else { | ||
// Not an edit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment refer to the first if
so should be moved above this new if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if it wasn't clear. I would like to have:
// Not an edit
if (seenEventIds.contains(notifiableEvent.eventId)) {
// we've already seen the event, lets skip
Timber.d("onNotifiableEventReceived(): skipping event, already seen")
} else {
seenEventIds.put(notifiableEvent.eventId)
eventList.add(notifiableEvent)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah 🤦 will do 👍
eventList.add(notifiableEvent) | ||
if (seenEventIds.contains(notifiableEvent.eventId)) { | ||
// we've already seen the event, lets' skip | ||
Timber.d("onNotifiableEventReceived(): skipping event, already seen}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, small }
at the end of the String
73d0ebd
to
926a123
Compare
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.Test | ||
|
||
class CircularCacheTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 for adding tests!
…ding and setting the value simpler - adds unit tests to show it working
926a123
to
fc793c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update!
Fixes #3437 - reappearing notifications after dismissing
Adds a in memory cache for keeping track of notification events we've already seen, this allows us to skip displaying already dismissed events received by the push flow which the /sync response then returns at a later point.
The cache is a simple circular buffer of 25 event ids to avoid us tracking every single event over the lifetime of the application. The cache size is a finger in the air estimate, could many users receive and dismiss 25+ push notifications before a sync response completes 🤔
*with a forced 5 second delay when syncing
The gif isn't very exciting, basically the after shows the notification no longer reappearing after dismissing