From 1eb1f4206dbf390067748823830a93638db4d744 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Wed, 5 Mar 2025 20:12:42 -0300 Subject: [PATCH] refactor: use db.kysely.updateTable rather than db.kysely.insertInto --- packages/ditto/storages/DittoRelayStore.ts | 30 +++++++++------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/ditto/storages/DittoRelayStore.ts b/packages/ditto/storages/DittoRelayStore.ts index fad27682..6f3cd791 100644 --- a/packages/ditto/storages/DittoRelayStore.ts +++ b/packages/ditto/storages/DittoRelayStore.ts @@ -161,7 +161,7 @@ export class DittoRelayStore implements NRelay { } // Recheck encountered after async ops. if (this.encounters.has(event.id)) { - throw new RelayError('duplicate', 'already have this event'); + return; } // Set the event as encountered after verifying the signature. this.encounters.set(event.id, true); @@ -293,23 +293,17 @@ export class DittoRelayStore implements NRelay { return; } - await db.kysely.insertInto('author_stats') - .values({ - pubkey: author.pubkey, - followers_count: 0, - following_count: 0, - notes_count: 0, - search: '', - }) - .onConflict((oc) => - oc.column('pubkey').doUpdateSet({ - nip05: null, - nip05_domain: null, - nip05_hostname: null, - nip05_last_verified_at: author.created_at, - }) - ) - .execute(); + try { + await db.kysely.updateTable('author_stats').set({ + nip05: null, + nip05_domain: null, + nip05_hostname: null, + nip05_last_verified_at: author.created_at, + }).where('pubkey', '=', author.pubkey) + .execute(); + } catch { + // nothing hahah + } } /** Parse kind 0 metadata and track indexes in the database. */