diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/nostr.ts | 19 | ||||
| -rw-r--r-- | lib/strfry.ts | 5 |
2 files changed, 18 insertions, 6 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); diff --git a/lib/strfry.ts b/lib/strfry.ts index 926ca429..65b77709 100644 --- a/lib/strfry.ts +++ b/lib/strfry.ts @@ -72,7 +72,10 @@ const exec = async (cmd: string, data = ""): Promise<Event[]> => // return r; // }; -export const load = (data) => exec(`echo '${data}' | /app/strfry import --no-verify\n`); +export const load = (data) => + exec( + `echo '${data.replace(/'/g, "'\\''")}' | /app/strfry import --no-verify\n`, + ); export const count = (f) => exec(`/app/strfry scan --count '${JSON.stringify(f)}'\n`); export const scan = (f) => exec(`/app/strfry scan '${JSON.stringify(f)}'\n`); |
