fix crash related to preloading events

Changelog-Fixed: fix crash related to preloading events
This commit is contained in:
Bryan Montz
2023-05-09 23:39:41 -05:00
parent 221fffe523
commit ce599badee

View File

@@ -10,6 +10,13 @@ import UIKit
class Profiles { class Profiles {
/// This queue is used to synchronize access to the profiles dictionary, which
/// prevents data races from crashing the app.
private var queue = DispatchQueue(label: "io.damus.profiles",
qos: .userInteractive,
attributes: .concurrent)
var profiles: [String: TimestampedProfile] = [:] var profiles: [String: TimestampedProfile] = [:]
var validated: [String: NIP05] = [:] var validated: [String: NIP05] = [:]
var nip05_pubkey: [String: String] = [:] var nip05_pubkey: [String: String] = [:]
@@ -28,14 +35,20 @@ class Profiles {
} }
func add(id: String, profile: TimestampedProfile) { func add(id: String, profile: TimestampedProfile) {
profiles[id] = profile queue.async(flags: .barrier) {
self.profiles[id] = profile
}
} }
func lookup(id: String) -> Profile? { func lookup(id: String) -> Profile? {
return profiles[id]?.profile queue.sync {
return profiles[id]?.profile
}
} }
func lookup_with_timestamp(id: String) -> TimestampedProfile? { func lookup_with_timestamp(id: String) -> TimestampedProfile? {
return profiles[id] queue.sync {
return profiles[id]
}
} }
} }