aboutsummaryrefslogtreecommitdiffstats
path: root/routes/events.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-12-29 16:07:13 -0800
committerAdam Soltys <[email protected]>2022-12-29 16:07:13 -0800
commit0f20d1cb0ca5a65ff6ae5fc4bb97657fc7ba4ee5 (patch)
tree4292426bcf7337e6f2b22f1dc4113e7a3f32716c /routes/events.js
parent33bfa7d2d4d74f4724d117ad58a825253e53d321 (diff)
downloadcoinos-server-0f20d1cb0ca5a65ff6ae5fc4bb97657fc7ba4ee5.tar.gz
coinos-server-0f20d1cb0ca5a65ff6ae5fc4bb97657fc7ba4ee5.zip
follower query caching
Diffstat (limited to 'routes/events.js')
-rw-r--r--routes/events.js21
1 files changed, 2 insertions, 19 deletions
diff --git a/routes/events.js b/routes/events.js
index 074579b0..fd2d97cd 100644
--- a/routes/events.js
+++ b/routes/events.js
@@ -1,7 +1,7 @@
import app from "$app";
import db from "$db";
import redis from "$lib/redis";
-import { coinos } from "$lib/nostr";
+import { coinos, q } from "$lib/nostr";
import store from "$lib/store";
import { wait } from "$lib/utils";
@@ -9,12 +9,6 @@ app.get("/nostr/:pubkey", async (req, res) => {
try {
let { pubkey } = req.params;
- store.fetching[pubkey] = true;
- store.timeouts[pubkey] = setTimeout(
- () => (store.fetching[pubkey] = false),
- 500
- );
-
let user = JSON.parse(await redis.get(`user:${pubkey}`));
if (!user) {
@@ -32,24 +26,13 @@ app.get("/nostr/:pubkey", async (req, res) => {
followers: []
};
- let { since } = user;
-
- coinos.subscribe(pubkey, {
- since,
+ await q(pubkey, {
kinds: [1],
authors: [pubkey]
});
- coinos.subscribe(`${pubkey}:followers`, {
- since,
- kinds: [3],
- "#p": [pubkey]
- });
-
- user.since = Math.round(Date.now() / 1000);
await redis.set(`user:${pubkey}`, JSON.stringify(user));
- await wait(() => !store.fetching[pubkey], 100, 100);
let ids = await redis.sMembers(pubkey);
let events = ids.length