damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit a324523b85527d14834189979f8cb8aea0924cd9
parent 1cf898e0b255d4d4e1f3efadd0120c8e390d8a57
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 23 Oct 2023 10:29:13 +0800

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.

Diffstat:
Mnostrdb/Ndb.swift | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git 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<Y>(txn: NdbTxn<Y>, 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