Fix UI bug with user search and fix race conditions on profiles NIP-05 cache

Signed-off-by: Terry Yiu <git@tyiu.xyz>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
2023-07-03 21:36:22 -04:00
committed by William Casarin
parent 3d0448a929
commit 640fbf23ea
5 changed files with 30 additions and 16 deletions

View File

@@ -726,7 +726,7 @@ func process_metadata_profile(our_pubkey: String, profiles: Profiles, profile: P
}
Task { @MainActor in
profiles.validated[ev.pubkey] = validated
profiles.set_validated(ev.pubkey, nip05: validated)
profiles.nip05_pubkey[nip05] = ev.pubkey
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
}

View File

@@ -50,7 +50,6 @@ extension Trie {
}
// Perform breadth-first search from matching branch and collect values from all descendants.
let exactMatches = Array(currentNode.exactMatchValues)
var substringMatches = Set<V>(currentNode.substringMatchValues)
var queue = Array(currentNode.children.values)
@@ -61,7 +60,8 @@ extension Trie {
queue.append(contentsOf: node.children.values)
}
return exactMatches + substringMatches
// Prioritize exact matches to be returned first, and then remove exact matches from the set of partial substring matches that are appended afterward.
return Array(currentNode.exactMatchValues) + (substringMatches.subtracting(currentNode.exactMatchValues))
}
/// Inserts value of type V into this trie for the specified key. This function stores all substring endings of the key, not only the key itself.