Background work was not being enqueued as unique work. This meant that every time a user opened the app, a new set of WorkRequests would get enqueued, but existing work requests would not be canceled. This was especially noticeable with BookmarksWorker, which is a PeriodicWorkRequest that ran every 8 hours. Every time a user opened the app, a new request would be scheduled to be run every 8 hours from that point.
The side-effects of this bug would be that work requests would compound and eventually attempt to make a large number of requests to the Stack Exchange API at once. This would result in 503s being returned and the "Network error" message to appear when making any API request.
This PR introduces a fix going forward that will check WorkManager for existing work based on new identifiers on each WorkRequest. If no currently enqueued work is found for any new identifier, cancel all WorkRequests since we can assume the user has a ton of non-unique work enqueued. Then schedule the unique work as normal (based on the ExistingWorkPolicy).
This overall disables offline bookmarks for now until a more sustainable solution is developed.
Checklist
[x] I self reviewed the submitted code
[x] I ran ./gradlew ktlintCheck detekt before submitting this PR
[x] I ran the app on a device/emulator or added unit tests to verify this change
Description
Fixes #93.
Background work was not being enqueued as unique work. This meant that every time a user opened the app, a new set of
WorkRequest
s would get enqueued, but existing work requests would not be canceled. This was especially noticeable withBookmarksWorker
, which is aPeriodicWorkRequest
that ran every 8 hours. Every time a user opened the app, a new request would be scheduled to be run every 8 hours from that point.The side-effects of this bug would be that work requests would compound and eventually attempt to make a large number of requests to the Stack Exchange API at once. This would result in 503s being returned and the "Network error" message to appear when making any API request.
This PR introduces a fix going forward that will check
WorkManager
for existing work based on new identifiers on eachWorkRequest
. If no currently enqueued work is found for any new identifier, cancel allWorkRequests
since we can assume the user has a ton of non-unique work enqueued. Then schedule the unique work as normal (based on theExistingWorkPolicy
).This overall disables offline bookmarks for now until a more sustainable solution is developed.
Checklist
./gradlew ktlintCheck detekt
before submitting this PR