From eef349f1e9aa19d3b1dd80489531f69361b1e55f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 15:05:59 -0500 Subject: [PATCH 1/2] Update stats before storing event --- src/pipeline.ts | 6 ++---- src/stats.ts | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index b3eea251..25cadb54 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -107,10 +107,8 @@ async function storeEvent(event: DittoEvent, signal?: AbortSignal): Promise[] = []; // Kind 3 is a special case - replace the count with the new list. if (event.kind === 3) { - prev = await maybeGetPrev(event); + prev = await getPrevEvent(event); if (!prev || event.created_at >= prev.created_at) { queries.push(updateFollowingCountQuery(event)); } @@ -153,12 +153,14 @@ function eventStatsQuery(diffs: EventStatDiff[]) { } /** Get the last version of the event, if any. */ -async function maybeGetPrev(event: NostrEvent): Promise { - const [prev] = await Storages.db.query([ - { kinds: [event.kind], authors: [event.pubkey], limit: 1 }, - ]); +async function getPrevEvent(event: NostrEvent): Promise { + if (NKinds.replaceable(event.kind) || NKinds.parameterizedReplaceable(event.kind)) { + const [prev] = await Storages.db.query([ + { kinds: [event.kind], authors: [event.pubkey], limit: 1 }, + ]); - return prev; + return prev; + } } /** Set the following count to the total number of unique "p" tags in the follow list. */ From 7feecab7232d284e42f70c0e0b942d8c1fa4346c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 15:25:56 -0500 Subject: [PATCH 2/2] stats: fix ambiguous column name error in Postgres? --- src/stats.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/stats.ts b/src/stats.ts index 1e95901c..21a4d979 100644 --- a/src/stats.ts +++ b/src/stats.ts @@ -119,9 +119,9 @@ function authorStatsQuery(diffs: AuthorStatDiff[]) { oc .column('pubkey') .doUpdateSet((eb) => ({ - followers_count: eb('followers_count', '+', eb.ref('excluded.followers_count')), - following_count: eb('following_count', '+', eb.ref('excluded.following_count')), - notes_count: eb('notes_count', '+', eb.ref('excluded.notes_count')), + followers_count: eb('author_stats.followers_count', '+', eb.ref('excluded.followers_count')), + following_count: eb('author_stats.following_count', '+', eb.ref('excluded.following_count')), + notes_count: eb('author_stats.notes_count', '+', eb.ref('excluded.notes_count')), })) ); } @@ -145,9 +145,9 @@ function eventStatsQuery(diffs: EventStatDiff[]) { oc .column('event_id') .doUpdateSet((eb) => ({ - replies_count: eb('replies_count', '+', eb.ref('excluded.replies_count')), - reposts_count: eb('reposts_count', '+', eb.ref('excluded.reposts_count')), - reactions_count: eb('reactions_count', '+', eb.ref('excluded.reactions_count')), + replies_count: eb('event_stats.replies_count', '+', eb.ref('excluded.replies_count')), + reposts_count: eb('event_stats.reposts_count', '+', eb.ref('excluded.reposts_count')), + reactions_count: eb('event_stats.reactions_count', '+', eb.ref('excluded.reactions_count')), })) ); }