Add last_updated_at column to pubkey_domains
This commit is contained in:
parent
8801debb1a
commit
c0c586b364
|
@ -70,6 +70,7 @@ interface UnattachedMediaRow {
|
||||||
interface PubkeyDomainRow {
|
interface PubkeyDomainRow {
|
||||||
pubkey: string;
|
pubkey: string;
|
||||||
domain: string;
|
domain: string;
|
||||||
|
last_updated_at: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sqliteWorker = new SqliteWorker();
|
const sqliteWorker = new SqliteWorker();
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { Kysely } from '@/deps.ts';
|
||||||
|
|
||||||
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
await db.schema
|
||||||
|
.alterTable('pubkey_domains')
|
||||||
|
.addColumn('last_updated_at', 'integer', (col) => col.notNull().defaultTo(0))
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
|
await db.schema.alterTable('pubkey_domains').dropColumn('last_updated_at').execute();
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ import { Conf } from '@/config.ts';
|
||||||
import { db } from '@/db.ts';
|
import { db } from '@/db.ts';
|
||||||
import { addRelays } from '@/db/relays.ts';
|
import { addRelays } from '@/db/relays.ts';
|
||||||
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
|
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
|
||||||
import { Debug, LNURL, type NostrEvent } from '@/deps.ts';
|
import { Debug, LNURL, type NostrEvent, sql } from '@/deps.ts';
|
||||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { isEphemeralKind } from '@/kinds.ts';
|
import { isEphemeralKind } from '@/kinds.ts';
|
||||||
import { DVM } from '@/pipeline/DVM.ts';
|
import { DVM } from '@/pipeline/DVM.ts';
|
||||||
|
@ -109,11 +109,15 @@ async function parseMetadata(event: NostrEvent, signal: AbortSignal): Promise<vo
|
||||||
// Track pubkey domain.
|
// Track pubkey domain.
|
||||||
try {
|
try {
|
||||||
const { domain } = parseNip05(nip05);
|
const { domain } = parseNip05(nip05);
|
||||||
await db
|
|
||||||
.insertInto('pubkey_domains')
|
await sql`
|
||||||
.values({ pubkey, domain })
|
INSERT INTO pubkey_domains (pubkey, domain, last_updated_at)
|
||||||
.execute()
|
VALUES (${pubkey}, ${domain}, ${event.created_at})
|
||||||
.catch(debug);
|
ON CONFLICT(pubkey) DO UPDATE SET
|
||||||
|
domain = excluded.domain,
|
||||||
|
last_updated_at = excluded.last_updated_at
|
||||||
|
WHERE excluded.last_updated_at > pubkey_domains.last_updated_at
|
||||||
|
`.execute(db);
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ Deno.test('query events with domain search filter', async () => {
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.insertInto('pubkey_domains')
|
.insertInto('pubkey_domains')
|
||||||
.values({ pubkey: event1.pubkey, domain: 'localhost:8000' })
|
.values({ pubkey: event1.pubkey, domain: 'localhost:8000', last_updated_at: event1.created_at })
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals(await eventsDB.query([{ kinds: [1], search: 'domain:localhost:8000' }]), [event1]);
|
assertEquals(await eventsDB.query([{ kinds: [1], search: 'domain:localhost:8000' }]), [event1]);
|
||||||
|
|
Loading…
Reference in New Issue