From a324523b85527d14834189979f8cb8aea0924cd9 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 23 Oct 2023 10:29:13 +0800 Subject: [PATCH] ndb: new methods for profile fetched_at This adds a few methods to Ndb for reading and writing fetched_at stats. These are a way of tracking when we last tried to fetch profiles so that we don't need to keep fetching them. --- nostrdb/Ndb.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nostrdb/Ndb.swift b/nostrdb/Ndb.swift index e55c543ec..150b63fac 100644 --- a/nostrdb/Ndb.swift +++ b/nostrdb/Ndb.swift @@ -182,6 +182,25 @@ class Ndb { } } + func write_profile_last_fetched(pubkey: Pubkey, fetched_at: UInt64) { + let _ = pubkey.id.withUnsafeBytes { (ptr: UnsafeRawBufferPointer) -> () in + guard let p = ptr.baseAddress else { return } + ndb_write_last_profile_fetch(ndb.ndb, p, fetched_at) + } + } + + func read_profile_last_fetched(txn: NdbTxn, pubkey: Pubkey) -> UInt64? { + return pubkey.id.withUnsafeBytes { (ptr: UnsafeRawBufferPointer) -> UInt64? in + guard let p = ptr.baseAddress else { return nil } + let res = ndb_read_last_profile_fetch(&txn.txn, p) + if res == 0 { + return nil + } + + return res + } + } + func process_event(_ str: String) -> Bool { return str.withCString { cstr in return ndb_process_event(ndb.ndb, cstr, Int32(str.utf8.count)) != 0