A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(api): cap cache purge requests at 100 prefixes (#3694)
Hampusf7b45ccda9e0
diff --git a/fluxer_api/src/api/infrastructure/CachePurgeQueue.ts b/fluxer_api/src/api/infrastructure/CachePurgeQueue.tsindex 42a286d72..c9fe95a20 100644--- a/fluxer_api/src/api/infrastructure/CachePurgeQueue.ts+++ b/fluxer_api/src/api/infrastructure/CachePurgeQueue.ts@@ -12,6 +12,7 @@ const QUEUE_KEY = 'cache_purge:queue';const BUDGET_KEY = 'cache_purge:budget';const REJECTED_KEY = 'cache_purge:rejected';const MAX_TOKENS = 120;+const MAX_PREFIXES_PER_REQUEST = 100;const REFILL_RATE = 5;const REFILL_INTERVAL_MS = 1000;@@ -46,7 +47,7 @@ export class CachePurgeQueue implements IPurgeQueue {const batch = await this.kvClient.dequeuePurgeBatch(QUEUE_KEY,BUDGET_KEY,- MAX_TOKENS,+ MAX_PREFIXES_PER_REQUEST,MAX_TOKENS,REFILL_RATE,REFILL_INTERVAL_MS,diff --git a/fluxer_api/src/api/worker/tests/ProcessCachePurgeQueue.test.ts b/fluxer_api/src/api/worker/tests/ProcessCachePurgeQueue.test.tsindex 6194f5c07..37471593d 100644--- a/fluxer_api/src/api/worker/tests/ProcessCachePurgeQueue.test.ts+++ b/fluxer_api/src/api/worker/tests/ProcessCachePurgeQueue.test.ts@@ -128,6 +128,21 @@ describe('processCachePurgeQueue', () => {expect(await members(kvClient, REJECTED_KEY)).toEqual([]);});+ it('keeps every request within the Cloudflare limit of 100 prefixes', async () => {+ const {kvClient, queue} = createHarness();+ const urls = Array.from({length: 150}, (_, index) => `${MEDIA}/attachments/1/${index}/photo.png`);+ await queue.addUrls(urls);+ const requests = recordPurges((body) => new HttpResponse(null, {status: body.prefixes.length > 100 ? 400 : 200}));++ await processCachePurgeQueue({}, createTestWorkerHelpers());+ await kvClient.del(BUDGET_KEY);+ await processCachePurgeQueue({}, createTestWorkerHelpers());++ expect(requests.map((request) => request.body.prefixes.length)).toEqual([100, 50]);+ expect(await members(kvClient, REJECTED_KEY)).toEqual([]);+ expect(await members(kvClient, QUEUE_KEY)).toEqual([]);+ });+it('never queues a URL that is not a media CDN object', async () => {const {kvClient, queue} = createHarness();await queue.addUrls(['https://elsewhere.test/avatars/1/b35cc3d3', `${MEDIA}/avatars`, 'not-a-url']);diff --git a/fluxer_docs/src/content/docs/operator/reverse-proxy.mdx b/fluxer_docs/src/content/docs/operator/reverse-proxy.mdxindex 564ab3504..3e030db43 100644--- a/fluxer_docs/src/content/docs/operator/reverse-proxy.mdx+++ b/fluxer_docs/src/content/docs/operator/reverse-proxy.mdx@@ -119,6 +119,18 @@ If Cloudflare proxies your domain, change these settings in the Cloudflare dashb- Turn Bot Fight Mode off and don't add challenges for `/api/`, `/gateway` or `/livekit/`. The desktop and mobile apps can't solve a challenge.- Set the SSL/TLS encryption mode to "Full (strict)".+### Purging deleted media++Cloudflare keeps serving cached copies of media after someone deletes it, until the cached copy expires. Fluxer can ask Cloudflare to purge those copies straight away. Create an API token with the Zone Cache Purge permission for your zone, find the zone ID on the zone's overview page, and set these variables.++```bash+rexctl config set FLUXER_CACHE_PURGE_ADAPTER http+rexctl config set FLUXER_CACHE_PURGE_HTTP_ENDPOINT https://api.cloudflare.com/client/v4/zones/<zone id>/purge_cache+rexctl config set FLUXER_CACHE_PURGE_HTTP_TOKEN <api token>+```++Fluxer sends at most 100 prefixes per request, which is the most Cloudflare accepts. See [Environment variables](/operator/environment/#media) for the other cache purge settings.+## Voice and videoCall audio and video don't go through your proxy. They connect directly to the machine on TCP port 7881 and UDP port 7882, and both ports need to be open. A tunnel such as Cloudflare Tunnel can't forward them, and an instance you only serve through a tunnel has no voice or video calls.