ndb: switch profile queries to use transactions
this should ensure no crashing occurs when querying profiles
This commit is contained in:
@@ -9,11 +9,11 @@ import SwiftUI
|
||||
|
||||
struct MultiSearch {
|
||||
let hashtag: String
|
||||
let profiles: [SearchedUser]
|
||||
let profiles: [Pubkey]
|
||||
}
|
||||
|
||||
enum Search: Identifiable {
|
||||
case profiles([SearchedUser])
|
||||
case profiles([Pubkey])
|
||||
case hashtag(String)
|
||||
case profile(Pubkey)
|
||||
case note(NoteId)
|
||||
@@ -49,10 +49,10 @@ struct InnerSearchResults: View {
|
||||
}
|
||||
}
|
||||
|
||||
func ProfilesSearch(_ results: [SearchedUser]) -> some View {
|
||||
func ProfilesSearch(_ results: [Pubkey]) -> some View {
|
||||
return LazyVStack {
|
||||
ForEach(results) { prof in
|
||||
ProfileSearchResult(pk: prof.pubkey)
|
||||
ForEach(results, id: \.id) { pk in
|
||||
ProfileSearchResult(pk: pk)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,27 +171,23 @@ func make_hashtagable(_ str: String) -> String {
|
||||
return String(new.filter{$0 != " "})
|
||||
}
|
||||
|
||||
func search_profiles(profiles: Profiles, search: String) -> [SearchedUser] {
|
||||
func search_profiles(profiles: Profiles, search: String) -> [Pubkey] {
|
||||
// Search by hex pubkey.
|
||||
if let pubkey = hex_decode_pubkey(search),
|
||||
let profile = profiles.lookup(id: pubkey)
|
||||
profiles.lookup_key_by_pubkey(pubkey) != nil
|
||||
{
|
||||
return [SearchedUser(profile: profile, pubkey: pubkey)]
|
||||
return [pubkey]
|
||||
}
|
||||
|
||||
// Search by npub pubkey.
|
||||
if search.starts(with: "npub"),
|
||||
let bech32_key = decode_bech32_key(search),
|
||||
case Bech32Key.pub(let pk) = bech32_key,
|
||||
let profile = profiles.lookup(id: pk)
|
||||
profiles.lookup_key_by_pubkey(pk) != nil
|
||||
{
|
||||
return [SearchedUser(profile: profile, pubkey: pk)]
|
||||
return [pk]
|
||||
}
|
||||
|
||||
let new = search.lowercased()
|
||||
let matched_pubkeys = profiles.user_search_cache.search(key: new)
|
||||
|
||||
return matched_pubkeys
|
||||
.map { SearchedUser(profile: profiles.lookup(id: $0), pubkey: $0) }
|
||||
.filter { $0.profile != nil }
|
||||
return profiles.user_search_cache.search(key: new)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user