From 65d84fd043f6cb36683bfcccf73560ab8d7d20ea Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 12 Jun 2017 10:21:35 -0400 Subject: [PATCH] Throttle profile fetch and retry on failure. // FREEBIE --- Signal/src/ProfileFetcherJob.swift | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Signal/src/ProfileFetcherJob.swift b/Signal/src/ProfileFetcherJob.swift index e6f719e46..dc8910c68 100644 --- a/Signal/src/ProfileFetcherJob.swift +++ b/Signal/src/ProfileFetcherJob.swift @@ -40,16 +40,20 @@ class ProfileFetcherJob: NSObject { public func getProfile(recipientId: String, remainingRetries: Int = 3) { - if let lastDate = ProfileFetcherJob.fetchDateMap[recipientId] { - let lastTimeInterval = fabs(lastDate.timeIntervalSinceNow) - // Don't check a profile more often than every N minutes. - let kGetProfileMaxFrequencySeconds = 60.0 * 5.0 - if lastTimeInterval < kGetProfileMaxFrequencySeconds { - Logger.info("\(self.TAG) skipping getProfile: \(recipientId), lastTimeInterval: \(lastTimeInterval)") - return + // Only throttle profile fetch in production builds in order to + // facilitate debugging. + if !_isDebugAssertConfiguration() { + if let lastDate = ProfileFetcherJob.fetchDateMap[recipientId] { + let lastTimeInterval = fabs(lastDate.timeIntervalSinceNow) + // Don't check a profile more often than every N minutes. + let kGetProfileMaxFrequencySeconds = 60.0 * 5.0 + if lastTimeInterval < kGetProfileMaxFrequencySeconds { + Logger.info("\(self.TAG) skipping getProfile: \(recipientId), lastTimeInterval: \(lastTimeInterval)") + return + } } + ProfileFetcherJob.fetchDateMap[recipientId] = Date() } - ProfileFetcherJob.fetchDateMap[recipientId] = Date() Logger.error("\(self.TAG) getProfile: \(recipientId)")