ndb: switch to nostrdb notes

This is a refactor of the codebase to use a more memory-efficient
representation of notes. It should also be much faster at decoding since
we're using a custom C json parser now.

Changelog-Changed: Improved memory usage and performance when processing events
This commit is contained in:
William Casarin
2023-07-26 08:46:44 -07:00
parent 55bbe8f855
commit cebd1f48ca
110 changed files with 2153 additions and 1799 deletions

View File

@@ -10,9 +10,13 @@ import CoreImage.CIFilterBuiltins
struct ProfileScanResult: Equatable {
let pubkey: Pubkey
init(hex: String) {
self.pubkey = hex
init?(hex: String) {
guard let pk = hex_decode(hex).map({ bytes in Pubkey(Data(bytes)) }) else {
return nil
}
self.pubkey = pk
}
init?(string: String) {
@@ -25,14 +29,17 @@ struct ProfileScanResult: Equatable {
str.removeFirst("nostr:".count)
}
if let _ = hex_decode(str), str.count == 64 {
self = .init(hex: str)
if let decoded = hex_decode(str),
str.count == 64
{
self.pubkey = Pubkey(Data(decoded))
return
}
if str.starts(with: "npub"), let b32 = try? bech32_decode(str) {
let hex = hex_encode(b32.data)
self = .init(hex: hex)
if str.starts(with: "npub"),
let b32 = try? bech32_decode(str)
{
self.pubkey = Pubkey(b32.data)
return
}
@@ -56,14 +63,6 @@ struct QRCodeView: View {
let generator = UIImpactFeedbackGenerator(style: .light)
var maybe_key: String? {
guard let key = bech32_pubkey(pubkey) else {
return nil
}
return key
}
@ViewBuilder
func navImage(systemImage: String) -> some View {
Image(systemName: systemImage)
@@ -143,18 +142,16 @@ struct QRCodeView: View {
Spacer()
if let key = maybe_key {
Image(uiImage: generateQRCode(pubkey: "nostr:" + key))
.interpolation(.none)
.resizable()
.scaledToFit()
.frame(width: 300, height: 300)
.cornerRadius(10)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(DamusColors.white, lineWidth: 5.0))
.shadow(radius: 10)
}
Image(uiImage: generateQRCode(pubkey: "nostr:" + pubkey.npub))
.interpolation(.none)
.resizable()
.scaledToFit()
.frame(width: 300, height: 300)
.cornerRadius(10)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(DamusColors.white, lineWidth: 5.0))
.shadow(radius: 10)
Spacer()
Text("Follow me on Nostr", comment: "Text on QR code view to prompt viewer looking at screen to follow the user.")