mirror of
git://jb55.com/damus
synced 2024-09-05 21:03:51 +00:00
nostrdb/index: write kind index when processing notes
We have a kind index database now, so write to it when processing notes Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
bfd78c01ca
commit
ff60f8a2db
@ -814,6 +814,13 @@ static inline void ndb_tsid_init(struct ndb_tsid *key, unsigned char *id,
|
|||||||
key->timestamp = timestamp;
|
key->timestamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void ndb_u64_tsid_init(struct ndb_tsid *key, uint64_t integer,
|
||||||
|
uint64_t timestamp)
|
||||||
|
{
|
||||||
|
key->integer = integer;
|
||||||
|
key->timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
// useful for range-searching for the latest key with a clustered created_at timen
|
// useful for range-searching for the latest key with a clustered created_at timen
|
||||||
static inline void ndb_tsid_high(struct ndb_tsid *key, const unsigned char *id)
|
static inline void ndb_tsid_high(struct ndb_tsid *key, const unsigned char *id)
|
||||||
{
|
{
|
||||||
@ -1844,6 +1851,32 @@ static int ndb_write_note_id_index(struct ndb_txn *txn, struct ndb_note *note,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ndb_write_note_kind_index(struct ndb_txn *txn, struct ndb_note *note,
|
||||||
|
uint64_t note_key)
|
||||||
|
{
|
||||||
|
struct ndb_u64_tsid tsid;
|
||||||
|
int rc;
|
||||||
|
MDB_val key, val;
|
||||||
|
MDB_dbi kind_db;
|
||||||
|
|
||||||
|
ndb_u64_tsid_init(&tsid, note->kind, note->created_at);
|
||||||
|
|
||||||
|
key.mv_data = &tsid;
|
||||||
|
key.mv_size = sizeof(tsid);
|
||||||
|
val.mv_data = ¬e_key;
|
||||||
|
val.mv_size = sizeof(note_key);
|
||||||
|
|
||||||
|
kind_db = txn->lmdb->dbs[NDB_DB_NOTE_KIND];
|
||||||
|
|
||||||
|
if ((rc = mdb_put(txn->mdb_txn, id_db, &key, &val, 0))) {
|
||||||
|
ndb_debug("write note kind index to db failed: %s\n",
|
||||||
|
mdb_strerror(rc));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static uint64_t ndb_write_note(struct ndb_txn *txn,
|
static uint64_t ndb_write_note(struct ndb_txn *txn,
|
||||||
struct ndb_writer_note *note)
|
struct ndb_writer_note *note)
|
||||||
{
|
{
|
||||||
@ -1873,6 +1906,10 @@ static uint64_t ndb_write_note(struct ndb_txn *txn,
|
|||||||
if (!ndb_write_note_id_index(txn, note->note, note_key))
|
if (!ndb_write_note_id_index(txn, note->note, note_key))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
// write note kind index
|
||||||
|
if (!ndb_write_note_kind_index(txn, note->note, note_key))
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (note->note->kind == 7) {
|
if (note->note->kind == 7) {
|
||||||
ndb_write_reaction_stats(txn, note->note);
|
ndb_write_reaction_stats(txn, note->note);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user