Skip to content

Commit 5323553

Browse files
committed
Improved reliability of configuration fetch and event hero storage
1 parent 0b5b43c commit 5323553

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Packages/ConfCore/ConfCore/AppleAPIClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public final class AppleAPIClient: Logging, Signposting {
196196
}
197197

198198
currentConfigRequest?.cancel()
199-
currentConfigRequest = configResource.loadIfNeeded()
199+
currentConfigRequest = configResource.load()
200200
}
201201

202202
}

Packages/ConfCore/ConfCore/Storage.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,23 @@ public final class Storage: Logging, Signposting {
332332
return
333333
}
334334

335-
performSerializedBackgroundWrite(disableAutorefresh: false, completionBlock: completion) { backgroundRealm in
335+
performSerializedBackgroundWrite(disableAutorefresh: false, completionBlock: completion) { [weak self] backgroundRealm in
336+
guard let self else { return }
337+
336338
// We currently only care about whatever the latest event hero is.
337339
let existingHeroData = backgroundRealm.objects(EventHero.self)
338-
backgroundRealm.delete(existingHeroData)
339-
}
340+
if !existingHeroData.isEmpty {
341+
self.log.info("Removing existing event hero")
342+
backgroundRealm.delete(existingHeroData)
343+
}
340344

341-
guard let hero = response.eventHero else {
342-
log.debug("Config response didn't contain an event hero")
343-
return
344-
}
345+
if let hero = response.eventHero {
346+
self.log.info("Storing event hero \(hero.identifier, privacy: .public)")
345347

346-
performSerializedBackgroundWrite(disableAutorefresh: false, completionBlock: completion) { backgroundRealm in
347-
backgroundRealm.add(hero, update: .modified)
348+
backgroundRealm.add(hero, update: .modified)
349+
} else {
350+
self.log.info("Config response had no event hero")
351+
}
348352
}
349353
}
350354

0 commit comments

Comments
 (0)