diff --git a/src/db.ts b/src/db.ts index 2d6b4d7..152b198 100644 --- a/src/db.ts +++ b/src/db.ts @@ -70,6 +70,7 @@ interface UnattachedMediaRow { interface PubkeyDomainRow { pubkey: string; domain: string; + last_updated_at: number; } const sqliteWorker = new SqliteWorker(); diff --git a/src/db/migrations/016_pubkey_domains_updated_at.ts b/src/db/migrations/016_pubkey_domains_updated_at.ts new file mode 100644 index 0000000..3a000c1 --- /dev/null +++ b/src/db/migrations/016_pubkey_domains_updated_at.ts @@ -0,0 +1,12 @@ +import { Kysely } from '@/deps.ts'; + +export async function up(db: Kysely): Promise { + await db.schema + .alterTable('pubkey_domains') + .addColumn('last_updated_at', 'integer', (col) => col.notNull().defaultTo(0)) + .execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema.alterTable('pubkey_domains').dropColumn('last_updated_at').execute(); +} diff --git a/src/pipeline.ts b/src/pipeline.ts index 8ab6b89..691afdf 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -3,7 +3,7 @@ import { Conf } from '@/config.ts'; import { db } from '@/db.ts'; import { addRelays } from '@/db/relays.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 { isEphemeralKind } from '@/kinds.ts'; import { DVM } from '@/pipeline/DVM.ts'; @@ -109,11 +109,15 @@ async function parseMetadata(event: NostrEvent, signal: AbortSignal): Promise pubkey_domains.last_updated_at + `.execute(db); } catch (_e) { // do nothing } diff --git a/src/storages/events-db.test.ts b/src/storages/events-db.test.ts index 713c94f..3481e0e 100644 --- a/src/storages/events-db.test.ts +++ b/src/storages/events-db.test.ts @@ -36,7 +36,7 @@ Deno.test('query events with domain search filter', async () => { await db .insertInto('pubkey_domains') - .values({ pubkey: event1.pubkey, domain: 'localhost:8000' }) + .values({ pubkey: event1.pubkey, domain: 'localhost:8000', last_updated_at: event1.created_at }) .execute(); assertEquals(await eventsDB.query([{ kinds: [1], search: 'domain:localhost:8000' }]), [event1]);