Skip to content

Commit

Permalink
ndb: new methods for profile fetched_at
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jb55 committed Oct 23, 2023
1 parent 1cf898e commit a324523
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions nostrdb/Ndb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a324523

Please sign in to comment.