pipeline: ensure event doesn't already exist in DB
This commit is contained in:
parent
b9922f96a0
commit
a30cdec79b
|
@ -35,6 +35,7 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
|
||||||
}
|
}
|
||||||
if (!(await verifyEventWorker(event))) return;
|
if (!(await verifyEventWorker(event))) return;
|
||||||
if (encounterEvent(event)) return;
|
if (encounterEvent(event)) return;
|
||||||
|
if (await existsInDB(event)) return;
|
||||||
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
||||||
|
|
||||||
if (event.kind !== 24133) {
|
if (event.kind !== 24133) {
|
||||||
|
@ -84,6 +85,13 @@ function encounterEvent(event: NostrEvent): boolean {
|
||||||
return encountered;
|
return encountered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check if the event already exists in the database. */
|
||||||
|
async function existsInDB(event: DittoEvent): Promise<boolean> {
|
||||||
|
const store = await Storages.db();
|
||||||
|
const events = await store.query([{ ids: [event.id], limit: 1 }]);
|
||||||
|
return events.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Hydrate the event with the user, if applicable. */
|
/** Hydrate the event with the user, if applicable. */
|
||||||
async function hydrateEvent(event: DittoEvent, signal: AbortSignal): Promise<void> {
|
async function hydrateEvent(event: DittoEvent, signal: AbortSignal): Promise<void> {
|
||||||
await hydrateEvents({ events: [event], store: await Storages.db(), signal });
|
await hydrateEvents({ events: [event], store: await Storages.db(), signal });
|
||||||
|
|
Loading…
Reference in New Issue