mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
handle event insertion errors with warning
This commit is contained in:
parent
0b6ca9dfea
commit
e7f5535bd2
1 changed files with 14 additions and 2 deletions
|
|
@ -29,6 +29,18 @@ const importUsers = async (
|
|||
const notes = new Set<string>();
|
||||
const { profilesOnly = false } = opts || {};
|
||||
|
||||
const put = async (event: NostrEvent) => {
|
||||
try {
|
||||
await doEvent(event);
|
||||
} catch (error) {
|
||||
if (error.message.includes('violates unique constraint')) {
|
||||
console.warn(`Skipping existing event ${event.id}...`);
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await Promise.all(relays.map(async (relay) => {
|
||||
if (!relay.startsWith('wss://')) console.error(`Invalid relay url ${relay}`);
|
||||
const conn = new NRelay1(relay);
|
||||
|
|
@ -49,7 +61,7 @@ const importUsers = async (
|
|||
if (kind === 1 && !notes.has(event.id)) {
|
||||
// add the event to eventsDB only if it has not been found already.
|
||||
notes.add(event.id);
|
||||
await doEvent(event);
|
||||
await put(event);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +76,7 @@ const importUsers = async (
|
|||
for (const user in profiles) {
|
||||
const profile = profiles[user];
|
||||
for (const kind in profile) {
|
||||
await doEvent(profile[kind]);
|
||||
await put(profile[kind]);
|
||||
}
|
||||
|
||||
let name = user;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue