commit f43459cc61c8b718ee9a8d5e8104e305a11f9f23
parent 322375397f4103f2b9838f075864f9491bd20fe9
Author: William Casarin <jb55@jb55.com>
Date: Thu, 28 Sep 2023 04:51:47 +0200
db: add ndb_read_last_profile_fetch
Diffstat:
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/nostrdb.c b/nostrdb.c
@@ -584,7 +584,6 @@ static void *ndb_lookup_by_key(struct ndb_txn *txn, uint64_t key,
if (mdb_get(txn->mdb_txn, txn->ndb->lmdb.dbs[store], &k, &v)) {
ndb_debug("ndb_get_profile_by_pubkey: mdb_get note failed\n");
- mdb_txn_abort(txn->mdb_txn);
return NULL;
}
@@ -665,6 +664,17 @@ void *ndb_get_profile_by_key(struct ndb_txn *txn, uint64_t key, size_t *len)
return ndb_lookup_by_key(txn, key, NDB_DB_PROFILE, len);
}
+uint64_t ndb_read_last_profile_fetch(struct ndb_txn *txn, uint64_t profile_key)
+{
+ size_t len;
+ void *ret = ndb_lookup_by_key(txn, profile_key, NDB_DB_PROFILE_LAST_FETCH, &len);
+ if (ret == NULL)
+ return 0;
+ assert(len == sizeof(uint64_t));
+ return *((uint64_t*)ret);
+}
+
+
static int ndb_has_note(MDB_txn *txn, struct ndb_lmdb *lmdb, const unsigned char *id)
{
MDB_val val;
diff --git a/nostrdb.h b/nostrdb.h
@@ -198,6 +198,7 @@ int ndb_search_profile_next(struct ndb_search *search);
void ndb_search_profile_end(struct ndb_search *search);
void ndb_end_query(struct ndb_txn *);
int ndb_write_last_profile_fetch(struct ndb *ndb, uint64_t profile_key, uint64_t fetched_at);
+uint64_t ndb_read_last_profile_fetch(struct ndb_txn *txn, uint64_t profile_key);
void *ndb_get_profile_by_pubkey(struct ndb_txn *txn, const unsigned char *pubkey, size_t *len, uint64_t *primkey);
void *ndb_get_profile_by_key(struct ndb_txn *txn, uint64_t key, size_t *len);
uint64_t ndb_get_notekey_by_id(struct ndb_txn *txn, const unsigned char *id);