Hook up caching on iOS
This commit is contained in:
parent
17cede4a14
commit
cbe0fd6f0e
|
@ -126,7 +126,18 @@ public final class LokiAPI : NSObject {
|
|||
if timeSinceLastUpdate > deviceLinkUpdateInterval {
|
||||
storage.dbReadConnection.read { transaction in
|
||||
let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey
|
||||
LokiStorageAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done { _ in getDestinations() }.catch { seal.reject($0) }
|
||||
LokiStorageAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done { _ in
|
||||
getDestinations()
|
||||
lastDeviceLinkUpdate[hexEncodedPublicKey] = Date()
|
||||
}.catch { error in
|
||||
if case LokiDotNetAPI.Error.parsingFailed = error {
|
||||
// If it's a parsing error then just cache
|
||||
getDestinations()
|
||||
lastDeviceLinkUpdate[hexEncodedPublicKey] = Date()
|
||||
} else {
|
||||
seal.reject(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getDestinations()
|
||||
|
|
|
@ -96,13 +96,6 @@ public final class LokiStorageAPI : LokiDotNetAPI {
|
|||
storage.setDeviceLinks(deviceLinks, in: transaction)
|
||||
}
|
||||
return deviceLinks
|
||||
}.recover { _ -> Promise<Set<DeviceLink>> in
|
||||
// If we error out at any time then fallback to the device links we have in storage
|
||||
var deviceLinks = Set<DeviceLink>()
|
||||
storage.dbReadConnection.read { transaction in
|
||||
deviceLinks = storage.getDeviceLinks(for: hexEncodedPublicKey, in: transaction)
|
||||
}
|
||||
return Promise.value(deviceLinks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue