-
Notifications
You must be signed in to change notification settings - Fork 445
Fix #3113: Fetch adblock data every 6 hours. #3130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,19 @@ class AdblockResourceDownloader { | |
Preferences.Shields.useRegionAdBlock.observe(from: self) | ||
} | ||
|
||
/// Initialized with year 1970 to force adblock fetch at first launch. | ||
private(set) var lastFetchDate = Date(timeIntervalSince1970: 0) | ||
|
||
func startLoading() { | ||
AdblockResourceDownloader.shared.regionalAdblockResourcesSetup() | ||
AdblockResourceDownloader.shared.generalAdblockResourcesSetup() | ||
let now = Date() | ||
let fetchInterval = AppConstants.buildChannel.isPublic ? 6.hours : 10.minutes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocked to decide on fetch interval, i like to fetch more often than 24hours, set it to 6 for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add some randomization to this so it's not as much of a user fingerprint? ex: each time the fetch is supposed to occur, delay it by a random amount between 1 and 10 minutes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @diracdeltas This will only be non-random if the user happens to open their phone every 6 hours since it only triggered on app foreground, not on a specific timer. |
||
|
||
if now.timeIntervalSince(lastFetchDate) >= fetchInterval { | ||
lastFetchDate = now | ||
|
||
AdblockResourceDownloader.shared.regionalAdblockResourcesSetup() | ||
AdblockResourceDownloader.shared.generalAdblockResourcesSetup() | ||
} | ||
} | ||
|
||
func regionalAdblockResourcesSetup() { | ||
|
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.
I have a suggestion. what do you think about adding resource downloading into also
applicationDidEnterBackground
.Use background task and use that window efficiently. We can define a background task with
and have an background task finish method like
and also we can have completion block from AdBlockResourceDownloader and end the task If operation is success.
And since we have also resource downloading in foreground this will help us improving the download experience and utilize the background window
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.
overkill imo, why would you want to download it both when the app goes in background and in foreground?
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.
If we will download while going to background using background task, it will not need to download while app is coming foreground and occupy a thread and do processing.
Why we need to add both(background/foreground) is background task can initiate processes that doesnt take too long and there is no guarantee it will succeed so in that case foreground can initialize the process if it is needed.
But yes this is a suggestion, not necessary.