Stop polling when current page (tab) isn't being viewed
Context:
We're currently using setInterval to poll for updates to data in ImporterStatus, MergeRequestWidget, Build & Notes. Soon we will be doing so more aggressively on all Issuables (MRs & Issues).
Current behavior:
As it is, when the user is viewing a page where polling occurs, and then they switch to another tab, we continue polling for updates in the background, even though the page is now hidden from view.
Given that many users keep many tabs open at a time (occasionally, probably even for the same page) and given that we will be polling more frequently on popular pages (e.g. on Issues and Merge Requests), this seems like a quick performance win. Specifically, it would mean an n-times reduction in polls to the server, where n is the number of tabs the user has open in their browser.
Proposed solution:
The pagevisibility event browser API allows us to listen for changes to the current tab's visibility and pause and resume polling accordingly.
If a user has 10 tabs open to GitLab pages, each of which polls the server every 15 seconds, this upgrade would reduce the number of times they poll the server from 40/minute to 4/minute.
It would make sense to create a small class that coordinates setInterval activity, allowing for pausing and restarting polling against page visibility events. We should implement it where we poll currently, and where we poll in the future.