From 46a9041b9792af00b8d66c664fdfa211f8fad9ae Mon Sep 17 00:00:00 2001 From: CJ_Clippy Date: Mon, 25 Aug 2025 12:19:36 -0800 Subject: [PATCH] deduplicate requests --- .gitea/workflows/builder.yaml | 2 -- playbooks/do-nothing/publish.abs | 19 ++++++++++-------- requirements.txt | 4 +++- services/rssapp/index.js | 34 ++++++++++++++++++++++---------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/builder.yaml b/.gitea/workflows/builder.yaml index 0b31d41..c1814bc 100644 --- a/.gitea/workflows/builder.yaml +++ b/.gitea/workflows/builder.yaml @@ -37,8 +37,6 @@ jobs: labels: | org.opencontainers.image.description=The Galaxy's Best VTuber hentai site org.opencontainers.image.title=our - org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}} - org.opencontainers.image.version={{version}} org.opencontainers.image.licenses=unlicense org.opencontainers.image.source=https://gitea.futureporn.net/futureporn/fp org.opencontainers.image.url=https://gitea.futureporn.net/futureporn/-/packages/container/our diff --git a/playbooks/do-nothing/publish.abs b/playbooks/do-nothing/publish.abs index 2fccc88..d5aeb02 100644 --- a/playbooks/do-nothing/publish.abs +++ b/playbooks/do-nothing/publish.abs @@ -2,24 +2,27 @@ #! /usr/local/bin/abs -echo(" * Remux the .ts to .mp4 ") +echo(" * Remux the .ts to .mp4 using `ffmpeg -i 2025-08-25T00-12-24Z.ts -c copy projektmelody-chaturbate-2025-08-24.mp4") echo(" [Press Enter When Complete...]") _ = stdin() -echo(" * Temporarily serve the mp4 using `npx http-server ./serve` ") -echo(" [Press Enter When Complete...]") -_ = stdin() - - -echo(" * Generate a thumbnail -- bash <(curl -fsSL https://gitea.futureporn.net/futureporn/fp/raw/branch/main/packages/scripts/thumbnail-generator.sh) ./projektmelody-chaturbate-2025-02-12.mp4") -echo(" * Upload the .mp4 to Mux ") echo(" * Upload the .mp4 to Backblaze ") +echo(" * Generate a thumbnail -- bash <(curl -fsSL https://gitea.futureporn.net/futureporn/fp/raw/branch/main/packages/scripts/thumbnail-generator.sh) ./projektmelody-chaturbate-2025-02-12.mp4") +echo(" * Upload the thumbnail to Backblaze") +echo(" [Press Enter When Complete...]") +_ = stdin() + +echo(" * Upload the .mp4 to Mux ") echo(" * Add the .mp4 to IPFS -- sudo -u ipfs ipfs add --cid-version=1 ./projektmelody-chaturbate-2025-02-12.mp4") echo(" * Remote pin the IPFS CID") echo(" [Press Enter When Complete...]") _ = stdin() +echo(" * Create magnet link. ex: `torf ~/Downloads/projektmelody-chaturbate-2025-08-25.mp4 --notorrent --notracker --webseed https://futureporn-b2.b-cdn.net/projektmelody-chaturbate-2025-08-25.mp4'") +echo(" [Press Enter When Complete...]") +_ = stdin() + echo(" * Create a B2 File (.mp4) in Strapi") echo(" * Create a B2 File (thumbnail) in Strapi") diff --git a/requirements.txt b/requirements.txt index 2b54871..2b88f25 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,6 @@ pre-commit ggshield click ansible -ansible-lint \ No newline at end of file +ansible-lint +vcsi +torrentfile diff --git a/services/rssapp/index.js b/services/rssapp/index.js index 6399e10..77ebb91 100644 --- a/services/rssapp/index.js +++ b/services/rssapp/index.js @@ -20,6 +20,8 @@ const cache = new TTLCache({ ttl: 30 * 60 * 1000, // 30 minutes }); +const inflight = new Map(); + // Format date as YYYY-MM-DD_HH:mm:ss_UTC function formatTwitterDate(date) { const pad = (n) => String(n).padStart(2, "0"); @@ -74,28 +76,40 @@ function buildFeed(username, tweets) { fastify.get("/:username", async (request, reply) => { const { username } = request.params; + const key = username.toLowerCase(); - if (!env.WHITELIST.has(username.toLowerCase())) { + if (!env.WHITELIST.has(key)) { return reply.code(403).send({ error: "Forbidden username" }); } - // Serve from cache if exists - const cached = cache.get(username); + const cached = cache.get(key); if (cached) { fastify.log.info('sending cached data'); - fastify.log.info(cached); - return reply - .header("Content-Type", "application/rss+xml") - .send(cached.xml); + return reply.header("Content-Type", "application/rss+xml").send(cached.xml); } - const data = await getJson(username) + let dataPromise; - const xml = buildFeed(username, data); + if (inflight.has(key)) { + // Wait for the in-progress fetch + fastify.log.info('waiting for in-flight fetch'); + dataPromise = inflight.get(key); + } else { + // Start a new fetch + dataPromise = getJson(key); + inflight.set(key, dataPromise); + + // Ensure we remove from inflight map when done + dataPromise.finally(() => inflight.delete(key)); + } + + const data = await dataPromise; + + const xml = buildFeed(key, data); // Cache result - cache.set(username, { xml, timestamp: Date.now() }); + cache.set(key, { xml, timestamp: Date.now() }); return reply.header("Content-Type", "application/rss+xml").send(xml); });