mirror of
https://github.com/signalapp/Signal-iOS.git
synced 2025-12-05 01:10:41 +00:00
Use Cron for periodic profile refreshes
This commit is contained in:
@@ -665,13 +665,19 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
appReadiness.runNowOrWhenAppDidBecomeReadyAsync {
|
||||
StaleProfileFetcher(
|
||||
db: DependenciesBridge.shared.db,
|
||||
profileFetcher: SSKEnvironment.shared.profileFetcherRef,
|
||||
tsAccountManager: DependenciesBridge.shared.tsAccountManager
|
||||
).scheduleProfileFetches()
|
||||
}
|
||||
cron.schedulePeriodically(
|
||||
uniqueKey: .fetchStaleProfiles,
|
||||
approximateInterval: .day,
|
||||
mustBeRegistered: true,
|
||||
mustBeConnected: true,
|
||||
operation: {
|
||||
try await StaleProfileFetcher(
|
||||
db: DependenciesBridge.shared.db,
|
||||
profileFetcher: SSKEnvironment.shared.profileFetcherRef,
|
||||
tsAccountManager: DependenciesBridge.shared.tsAccountManager,
|
||||
).fetchSomeStaleProfiles()
|
||||
},
|
||||
)
|
||||
|
||||
let groupV2Updates = SSKEnvironment.shared.groupV2UpdatesRef
|
||||
cron.schedulePeriodically(
|
||||
|
||||
@@ -23,11 +23,8 @@ class StaleProfileFetcher {
|
||||
self.tsAccountManager = tsAccountManager
|
||||
}
|
||||
|
||||
func scheduleProfileFetches() {
|
||||
func fetchSomeStaleProfiles() async throws(CancellationError) {
|
||||
let staleServiceIds = db.read { tx -> [ServiceId] in
|
||||
guard tsAccountManager.registrationState(tx: tx).isRegistered else {
|
||||
return []
|
||||
}
|
||||
var staleServiceIds = [ServiceId]()
|
||||
Self.enumerateMissingAndStaleUserProfiles(now: Date(), tx: tx) { userProfile in
|
||||
switch userProfile.internalAddress {
|
||||
@@ -42,9 +39,15 @@ class StaleProfileFetcher {
|
||||
}
|
||||
return staleServiceIds
|
||||
}
|
||||
Task { [profileFetcher] in
|
||||
for serviceId in staleServiceIds.shuffled() {
|
||||
_ = try? await profileFetcher.fetchProfile(for: serviceId, context: .init(isOpportunistic: true))
|
||||
for serviceId in staleServiceIds.shuffled() {
|
||||
do {
|
||||
_ = try await profileFetcher.fetchProfile(for: serviceId, context: .init(isOpportunistic: true))
|
||||
} catch let error as CancellationError {
|
||||
throw error
|
||||
} catch ProfileFetcherError.skippingOpportunisticFetch {
|
||||
// We expect this to happen and can safely ignore it.
|
||||
} catch {
|
||||
Logger.warn("Couldn't fetch stale profile for \(serviceId): \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ public class Cron {
|
||||
case fetchDevices
|
||||
case fetchSenderCertificates
|
||||
case fetchStaleGroup
|
||||
case fetchStaleProfiles
|
||||
case fetchSubscriptionConfig
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user