commit 6845d0df47f4e247f5c9d0b0cd4dc1299bf7ba11
parent 8e79ad582ae38a23035c4dc7992d14af75ee914a
Author: William Casarin <jb55@jb55.com>
Date: Fri, 13 Dec 2024 17:31:47 -0800
nostrdb: migrate notes to have pubkey indices
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git 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 },
};