mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Remove pubkey_domains table
This commit is contained in:
parent
efbefd918a
commit
f6fe777e78
7 changed files with 35 additions and 22 deletions
|
|
@ -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;
|
||||
|
|
|
|||
22
src/db/migrations/048_rm_pubkey_domains.ts
Normal file
22
src/db/migrations/048_rm_pubkey_domains.ts
Normal 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();
|
||||
}
|
||||
|
|
@ -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[];
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue