diff options
| author | Adam Soltys <[email protected]> | 2025-01-23 12:22:42 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-23 12:22:42 -0800 |
| commit | af884d9710dd42c462437c02a53948b09d5d396f (patch) | |
| tree | d3c97ddddc9192aba60a55ef3202a4ea377e3a96 /lib/nostr.ts | |
| parent | 9662c2754834599a1074d12565279674c20af467 (diff) | |
| download | coinos-server-af884d9710dd42c462437c02a53948b09d5d396f.tar.gz coinos-server-af884d9710dd42c462437c02a53948b09d5d396f.zip | |
follows
Diffstat (limited to 'lib/nostr.ts')
| -rw-r--r-- | lib/nostr.ts | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/nostr.ts b/lib/nostr.ts index 21c254e3..9f31f6ad 100644 --- a/lib/nostr.ts +++ b/lib/nostr.ts @@ -151,12 +151,21 @@ export const getProfile = async (pubkey) => { export const getCount = async (pubkey) => { try { - const result = await scan({ authors: [pubkey], kinds: [3] }); - const follows = result.length - ? result[0].tags.filter((t) => t[0] === "p").length - : 0; + let follows = await g(`${pubkey}:follows:n`); + + if (!follows) { + const result = await get({ authors: [pubkey], kinds: [3] }); + follows = result ? result.tags.filter((t) => t[0] === "p").length : 0; + await db.set(`${pubkey}:follows:n`, follows, { EX: 300 }); + } + + let followers = await g(`${pubkey}:followers:n`); + + if (!followers) { + [followers] = await count({ "#p": [pubkey], kinds: [3] }); + await db.set(`${pubkey}:followers:n`, followers, { EX: 300 }); + } - const [followers] = await count({ "#p": [pubkey], kinds: [3] }); return { follows, followers }; } catch (e) { console.log(e); |
