Hook up caching on iOS

pull/56/head
Mikunj 6 years ago
parent 17cede4a14
commit cbe0fd6f0e

@ -126,7 +126,18 @@ public final class LokiAPI : NSObject {
if timeSinceLastUpdate > deviceLinkUpdateInterval { if timeSinceLastUpdate > deviceLinkUpdateInterval {
storage.dbReadConnection.read { transaction in storage.dbReadConnection.read { transaction in
let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey 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 { } else {
getDestinations() getDestinations()

@ -96,13 +96,6 @@ public final class LokiStorageAPI : LokiDotNetAPI {
storage.setDeviceLinks(deviceLinks, in: transaction) storage.setDeviceLinks(deviceLinks, in: transaction)
} }
return deviceLinks 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…
Cancel
Save