Optimize json processing and preloading

- Preload events when added to the EventHolder queue
- Remove relative time formatting from preloader. Just do it when event appears
- Process incoming json in a background queue by default

Changelog-Fixed: Fix wrong relative times on events
Changelog-Changed: Preload events when they are queued
This commit is contained in:
William Casarin
2023-05-03 09:18:09 -07:00
parent 3b541f2ec1
commit 39a324fd1e
10 changed files with 191 additions and 90 deletions

View File

@@ -8,20 +8,27 @@
import Foundation
class ProfileModel: ObservableObject, Equatable {
var events: EventHolder = EventHolder()
@Published var contacts: NostrEvent? = nil
@Published var following: Int = 0
@Published var relays: [String: RelayInfo]? = nil
@Published var progress: Int = 0
var events: EventHolder
let pubkey: String
let damus: DamusState
var seen_event: Set<String> = Set()
var sub_id = UUID().description
var prof_subid = UUID().description
init(pubkey: String, damus: DamusState) {
self.pubkey = pubkey
self.damus = damus
self.events = EventHolder(on_queue: { ev in
preload_events(state: damus, events: [ev])
})
}
func follows(pubkey: String) -> Bool {
guard let contacts = self.contacts else {
return false
@@ -47,11 +54,6 @@ class ProfileModel: ObservableObject, Equatable {
return .pubkey(pubkey)
}
init(pubkey: String, damus: DamusState) {
self.pubkey = pubkey
self.damus = damus
}
static func == (lhs: ProfileModel, rhs: ProfileModel) -> Bool {
return lhs.pubkey == rhs.pubkey
}