db/events: don't throw on duplicate events
This commit is contained in:
parent
ebd933126a
commit
77b09baa8c
|
@ -1,5 +1,5 @@
|
||||||
import { db, type TagRow } from '@/db.ts';
|
import { db, type TagRow } from '@/db.ts';
|
||||||
import { type Event, type Insertable } from '@/deps.ts';
|
import { type Event, type Insertable, SqliteError } from '@/deps.ts';
|
||||||
|
|
||||||
import type { DittoFilter, GetFiltersOpts } from '@/filter.ts';
|
import type { DittoFilter, GetFiltersOpts } from '@/filter.ts';
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ function insertEvent(event: Event): Promise<void> {
|
||||||
...event,
|
...event,
|
||||||
tags: JSON.stringify(event.tags),
|
tags: JSON.stringify(event.tags),
|
||||||
})
|
})
|
||||||
.executeTakeFirst();
|
.execute();
|
||||||
|
|
||||||
const tagCounts: Record<string, number> = {};
|
const tagCounts: Record<string, number> = {};
|
||||||
const tags = event.tags.reduce<Insertable<TagRow>[]>((results, tag) => {
|
const tags = event.tags.reduce<Insertable<TagRow>[]>((results, tag) => {
|
||||||
|
@ -48,6 +48,13 @@ function insertEvent(event: Event): Promise<void> {
|
||||||
.values(tags)
|
.values(tags)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
// Don't throw for duplicate events.
|
||||||
|
if (error instanceof SqliteError && error.code === 19) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ export {
|
||||||
export { generateSeededRsa } from 'https://gitlab.com/soapbox-pub/seeded-rsa/-/raw/v1.0.0/mod.ts';
|
export { generateSeededRsa } from 'https://gitlab.com/soapbox-pub/seeded-rsa/-/raw/v1.0.0/mod.ts';
|
||||||
export * as secp from 'npm:@noble/secp256k1@^2.0.0';
|
export * as secp from 'npm:@noble/secp256k1@^2.0.0';
|
||||||
export { LRUCache } from 'npm:lru-cache@^10.0.0';
|
export { LRUCache } from 'npm:lru-cache@^10.0.0';
|
||||||
export { DB as Sqlite } from 'https://deno.land/x/sqlite@v3.7.3/mod.ts';
|
export { DB as Sqlite, SqliteError } from 'https://deno.land/x/sqlite@v3.7.3/mod.ts';
|
||||||
export * as dotenv from 'https://deno.land/std@0.198.0/dotenv/mod.ts';
|
export * as dotenv from 'https://deno.land/std@0.198.0/dotenv/mod.ts';
|
||||||
export {
|
export {
|
||||||
FileMigrationProvider,
|
FileMigrationProvider,
|
||||||
|
|
Loading…
Reference in New Issue