commit 3d190a738834db21217591bcb840981f27a48595
parent 4a40c9987db3c32a16fea8c64346ef0ccf4618bd
Author: William Casarin <jb55@jb55.com>
Date: Thu, 1 Feb 2024 11:05:16 -0800
purple: fix crash in account cache
otherwise there is contention and tends to crash
Fixes: f06b88213985 ("purple: consolidate UserBadgeInfo with Account")
Changelog-Fixed: Fix crash when accessing cached purple accounts
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/damus/Models/Purple/DamusPurple.swift b/damus/Models/Purple/DamusPurple.swift
@@ -10,6 +10,8 @@ import Foundation
class DamusPurple: StoreObserverDelegate {
let settings: UserSettingsStore
let keypair: Keypair
+
+ @MainActor
var account_cache: [Pubkey: Account]
init(settings: UserSettingsStore, keypair: Keypair) {
@@ -49,6 +51,7 @@ class DamusPurple: StoreObserverDelegate {
return false
}
+ @MainActor
func get_maybe_cached_account(pubkey: Pubkey) async throws -> Account? {
if let account = self.account_cache[pubkey] {
return account
@@ -56,6 +59,7 @@ class DamusPurple: StoreObserverDelegate {
return try await fetch_account(pubkey: pubkey)
}
+ @MainActor
func fetch_account(pubkey: Pubkey) async throws -> Account? {
guard let data = try await self.get_account_data(pubkey: pubkey) ,
let account = Account.from(json_data: data) else {