Remove pubkey_domains table

This commit is contained in:
Alex Gleason 2025-02-11 21:49:58 -06:00
parent efbefd918a
commit f6fe777e78
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
7 changed files with 35 additions and 22 deletions

View file

@ -7,7 +7,6 @@ export interface DittoTables extends NPostgresSchema {
author_stats: AuthorStatsRow;
domain_favicons: DomainFaviconRow;
event_stats: EventStatsRow;
pubkey_domains: PubkeyDomainRow;
event_zaps: EventZapRow;
push_subscriptions: PushSubscriptionRow;
}
@ -45,12 +44,6 @@ interface AuthTokenRow {
created_at: Date;
}
interface PubkeyDomainRow {
pubkey: string;
domain: string;
last_updated_at: number;
}
interface DomainFaviconRow {
domain: string;
favicon: string;

View file

@ -0,0 +1,22 @@
import { Kysely } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await db.schema.dropTable('pubkey_domains').execute();
}
export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema
.createTable('pubkey_domains')
.ifNotExists()
.addColumn('pubkey', 'text', (col) => col.primaryKey())
.addColumn('domain', 'text', (col) => col.notNull())
.addColumn('last_updated_at', 'integer', (col) => col.notNull().defaultTo(0))
.execute();
await db.schema
.createIndex('pubkey_domains_domain_index')
.on('pubkey_domains')
.column('domain')
.ifNotExists()
.execute();
}

View file

@ -27,7 +27,6 @@ export interface EventStats {
/** Internal Event representation used by Ditto, including extra keys. */
export interface DittoEvent extends NostrEvent {
author?: DittoEvent;
author_domain?: string;
author_stats?: AuthorStats;
event_stats?: EventStats;
mentions?: DittoEvent[];

View file

@ -161,15 +161,6 @@ function isProtectedEvent(event: NostrEvent): boolean {
/** Hydrate the event with the user, if applicable. */
async function hydrateEvent(event: DittoEvent, signal: AbortSignal): Promise<void> {
await hydrateEvents({ events: [event], store: await Storages.db(), signal });
const kysely = await Storages.kysely();
const domain = await kysely
.selectFrom('pubkey_domains')
.select('domain')
.where('pubkey', '=', event.pubkey)
.executeTakeFirst();
event.author_domain = domain?.domain;
}
/** Maybe store the event, if eligible. */

View file

@ -47,8 +47,16 @@ Deno.test('query events with domain search filter', async () => {
assertEquals(await store.query([{ search: '' }]), [event1]);
await kysely
.insertInto('pubkey_domains')
.values({ pubkey: event1.pubkey, domain: 'localhost:4036', last_updated_at: event1.created_at })
.insertInto('author_stats')
.values({
pubkey: event1.pubkey,
nip05_domain: 'localhost:4036',
nip05_last_verified_at: event1.created_at,
followers_count: 0,
following_count: 0,
notes_count: 0,
search: '',
})
.execute();
assertEquals(await store.query([{ kinds: [1], search: 'domain:localhost:4036' }]), [event1]);

View file

@ -371,9 +371,9 @@ class EventsDB extends NPostgres {
if (domains.size) {
let query = this.opts.kysely
.selectFrom('pubkey_domains')
.selectFrom('author_stats')
.select('pubkey')
.where('domain', 'in', [...domains]);
.where('nip05_domain', 'in', [...domains]);
if (filter.authors) {
query = query.where('pubkey', 'in', filter.authors);

View file

@ -61,7 +61,7 @@ export class InternalRelay implements NRelay {
typeof t === 'object' && t.key === 'domain'
) as { key: 'domain'; value: string } | undefined)?.value;
if (domain === event.author_domain) {
if (domain === event.author_stats?.nip05_domain) {
machina.push(purifyEvent(event));
break;
}