MPRIS: Use delay timer to fix update spam #1950
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
OK, since we have a little time to wait until KDE Connect 1.33.2 makes it to user devices (see #1931), I figure let's get a couple of other fixes in to the next release. This is a fix for the MPRIS spam issue I reported a few weeks ago, details in #1919. I've tested it, and it seems to work well enough — I sometimes still see two MPRIS packets being sent in a row, but that's still a lot better than 10-15 like before.
My only real issue with it is that the 250ms timer I'm using to deduplicate metadata updates is just so... arbitrary. That alone makes it feel like an imperfect solution, but it's better than nothing so I don't want to let the perfect be the enemy of the good. Thus, this PR. Commit message description follows...
Because the MPRIS plugin listens for metadata changes from players, and because it will create a new update packet for each change and immediately send it to the paired device, something like a media change (advancing in a playlist, for example) can cause 10-15 property changes in a span of milliseconds, potentially firing a barrage of 10-15
kdeconnect.mpris
packets at the device. Worse, because each of these packets contains a full metadata dump, they're 10-15 nearly identical packets, except for a single changed value.To mitigate this spam, start a 250ms timer running whenever the
_onPlayerChanged()
listener fires, and only create the update packet when the timer expires. Ignore any other_onPlayerChanged
signals while the timer is running.Responses to user actions or any
kdeconnect.mpris.request
packets received will be sent immediately, aborting any running timer, so responsiveness is not impacted.Fixes #1919