In T260860#6633233, @Gilles wrote:Now, in terms of performance. The live update mode generates a lot of requests. Those requests keep happening even when the browser tab is in the background. This must be changed to requests only happening when the current page/tab is in focus. There's no point running those updates for a tab that the user doesn't see.
Description
Description
Details
Details
Related Changes in Gerrit:
| Subject | Repo | Branch | Lines +/- | |
|---|---|---|---|---|
| Only run live updates while the tab is visible | mediawiki/extensions/GlobalWatchlist | master | +46 -7 |
Related Objects
Related Objects
Event Timeline
Comment Actions
Refs / code to draw from / things to consider
- ContentTranslation code - appears to depend on page visibility api, probably the easiest to implement
- EventLogging code - has some handling for browsers that don't implement the page visibility api
- https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
- https://www.mediawiki.org/wiki/Template:Compatibility_browser
- https://caniuse.com/pagevisibility
Of the supported browsers, the desktop browsers allow using the pagevisibility api, but the mobile ones don't always
- Safari (MW supports 5.1+, only available in 6.1+)
- iOS (MW supports 6.1+, only available in 7+)
- Android (MW supports 4.1+, only available in 81+ (though the numbering system changed in between))
T229239: Refresh target browser support for MW, dropping less-used browsers from Grade A to Grade C would solve the Safari and iOS support by dropping the versions that don't support the api
Not sure how to handle android
...that being said, this is geared towards desktops, not mobile views, and is not critical, so adding this handling when the page visibility api is available is better than nothing
Event handler should be attached in the "On ready initialization" for SpecialGlobalWatchlist.display.js, and in mounted for the vue version. If the visibility is hidden, and live updates is true, should set to paused, and if it is visible, and live updates is paused, should set it back to true.
Comment Actions
Change 643157 had a related patch set uploaded (by DannyS712; owner: DannyS712):
[mediawiki/extensions/GlobalWatchlist@master] Only run live updates while the tab is visible
Comment Actions
Have you considered using document.hasFocus() instead? It has better support for old mobile browsers, but might be a pain to use as the boolean value would need to be polled periodically (there's no event to listen to).
Comment Actions
I think the fact that there is no event rules it out for now, but I'll look into adding that in addition to using the pagevisibility api
Comment Actions
Test wiki created on Patch Demo by GDubuc (WMF) using patch(es) linked to this task:
http://patchdemo.wmflabs.org/wikis/234c3863feb3b9a0b8b1c1e0e2223b84/w/
Comment Actions
Test wiki created on Patch Demo by GDubuc (WMF) using patch(es) linked to this task:
http://patchdemo.wmflabs.org/wikis/f4d9b5e0597452dab7b4f3c8ae3d2928/w/
Comment Actions
Change 643157 merged by jenkins-bot:
[mediawiki/extensions/GlobalWatchlist@master] Only run live updates while the tab is visible
Comment Actions
Test wiki on Patch Demo by GDubuc (WMF) using patch(es) linked to this task was deleted:
https://patchdemo.wmflabs.org/wikis/234c3863feb3b9a0b8b1c1e0e2223b84/w/
Comment Actions
Test wiki on Patch Demo by GDubuc (WMF) using patch(es) linked to this task was deleted:
https://patchdemo.wmflabs.org/wikis/f4d9b5e0597452dab7b4f3c8ae3d2928/w/