db/events: don't throw on duplicate events

This commit is contained in:
Alex Gleason
2023-08-29 13:20:21 -05:00
parent ebd933126a
commit 77b09baa8c
2 changed files with 10 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
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';
@@ -23,7 +23,7 @@ function insertEvent(event: Event): Promise<void> {
...event,
tags: JSON.stringify(event.tags),
})
.executeTakeFirst();
.execute();
const tagCounts: Record<string, number> = {};
const tags = event.tags.reduce<Insertable<TagRow>[]>((results, tag) => {
@@ -48,6 +48,13 @@ function insertEvent(event: Event): Promise<void> {
.values(tags)
.execute();
}
}).catch((error) => {
// Don't throw for duplicate events.
if (error instanceof SqliteError && error.code === 19) {
return;
} else {
throw error;
}
});
}