From 6845d0df47f4e247f5c9d0b0cd4dc1299bf7ba11 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 13 Dec 2024 17:31:47 -0800 Subject: [PATCH] nostrdb: migrate notes to have pubkey indices Signed-off-by: William Casarin --- nostrdb/src/nostrdb.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/nostrdb/src/nostrdb.c b/nostrdb/src/nostrdb.c index 68a842bf..79354d36 100644 --- a/nostrdb/src/nostrdb.c +++ b/nostrdb/src/nostrdb.c @@ -1586,6 +1586,29 @@ cleanup: // Migrations // +// This was before we had note_profile_pubkey{,_kind} indices. Let's create them. +static int ndb_migrate_profile_indices(struct ndb *ndb) +{ + struct ndb_txn txn; + int count; + + if (!ndb_begin_rw_query(ndb, &txn)) { + fprintf(stderr, "ndb_migrate_profile_indices: ndb_begin_rw_query failed\n"); + return 0; + } + + enum ndb_dbs indices[] = {NDB_DB_NOTE_PUBKEY, NDB_DB_NOTE_PUBKEY_KIND}; + if ((count = ndb_rebuild_note_indices(&txn, indices, 2))) { + fprintf(stderr, "migrated %d notes to have pubkey and pubkey_kind indices\n", count); + ndb_end_query(&txn); + } else { + fprintf(stderr, "error migrating notes to have pubkey and pubkey_kind indices, aborting.\n"); + mdb_txn_abort(txn.mdb_txn); + } + + return count; +} + static int ndb_migrate_user_search_indices(struct ndb *ndb) { int rc; @@ -1908,7 +1931,8 @@ static int ndb_migrate_utf8_profile_names(struct ndb *ndb) static struct ndb_migration MIGRATIONS[] = { { .fn = ndb_migrate_user_search_indices }, { .fn = ndb_migrate_lower_user_search_indices }, - { .fn = ndb_migrate_utf8_profile_names } + { .fn = ndb_migrate_utf8_profile_names }, + { .fn = ndb_migrate_profile_indices }, };