From afbef8dd8dac9e1e71415914f2ecab7ce85f1fa5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 13 Oct 2024 23:40:32 -0700 Subject: cache count --- lib/nostr.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/nostr.ts b/lib/nostr.ts index 2e1dcd71..a58cb2c9 100644 --- a/lib/nostr.ts +++ b/lib/nostr.ts @@ -173,8 +173,10 @@ export let getCount = async (pubkey) => { follows = ev.tags .map((t) => t[0] === "p" && t[1]) .filter((p) => p && p.length === 64).length; - await s(`${pubkey}:follows:n`, follows); } + + follows ||= 0; + await s(`${pubkey}:follows:n`, follows); } if (!followers) { @@ -186,12 +188,11 @@ export let getCount = async (pubkey) => { if (f && f.content) { counts = JSON.parse(f.content); followers = counts[pubkey]; - await s(`${pubkey}:followers:n`, followers); } - } - follows ||= 0; - followers ||= 0; + followers ||= 0; + await s(`${pubkey}:followers:n`, followers); + } return { follows, followers }; }; -- cgit v1.2.3