Repository navigation
perf(d1): stop crawlers rendering public-dashboard filter permutations - #8
Merged
Merged
Conversation
…ations D1 hit 24.0B rows read in the 32 days to 2026-10-12, against 25B included. Nearly all of it was renders of Beam's own /public/ dashboard, with bingbot, PetalBot, DotBot and unverified scrapers walking its filter links. Each filter combination is a new URL that runs the full ~16-statement batch. Each guard runs before the first query: - robots.txt disallows /public/ and /embed/. The page sends noindex, and every same-page link (filters, chips, ranges) is rel=nofollow. - Filtered requests from verified bots (cf.verifiedBotCategory) or self-identified crawler UAs get a 403. - At most 2 filters. More than that 301s to the unfiltered view, and at the cap the page offers no link (or chart click) that adds a third. - The rendered page is cached in caches.default for 5 minutes, keyed on canonical params. The visibility lookup runs first, so making a dashboard private takes effect immediately. - The three filter-independent custom_events statements (~8.3B rows in 30 days) are cached per site and range, so filtered variants share them. They were the batch's last entries, so no positional index shifted. No KV writes: the Cache API has no write quota. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
D1 read 24.0B rows in the 32 days to 2026-10-12, against 25B included on Workers Paid. It peaked at 2.1B rows on 2026-09-29. Nearly all of it was renders of Beam's own
/public/dashboard (linked from the landing page as "Live stats"). It's the only public dashboard with real data, and its 43k events and 48k pageviews make each render expensive.A 2-minute
wrangler tailshowed 7 of 15 worker requests were/public/filter permutations, for example?range=30d&page=/for/framer&browser=Other&channel=Direct&referrer=Direct. They came from bingbot, PetalBot (Huawei), DotBot, and unverified Alibaba/residential-proxy scrapers. Every combination is a new URL that runs the full ~16-statement batch, and the filters aren't indexed, so they don't shrink the scan.This is the robots.txt + Cache-Control follow-up identified on 2026-09-04 and never shipped, plus guards for the scrapers robots.txt won't stop.
What changed
Each guard runs before the first query:
robots.txtDisallow: /public/and/embed/,noindexmeta andX-Robots-Tag,rel="nofollow"on every same-page linkcf.verifiedBotCategoryor crawler UAscaches.defaultfor 5 min, keyed on canonical paramscustom_eventsstatements (~8.3B rows/30d) cached per site and rangeNotes:
sites.publiclookup runs before the cache read, so making a dashboard private takes effect immediately rather than after the TTL.batchRes[n]above them shifted.botto be followed by/ ; ) -, so phone models like "Cubot X30" aren't treated as crawlers.Verification
npm run typecheckis cleannpm test: 130 pass, 0 fail (4 skipped as before), including 11 new tests intest/public-crawler-guard.test.ts. These assert on the SQL issued, not just the status code.npm run test:smoke: 128/128, against a dev server withPUBLIC_BASE_URL=http://localhost:8787, so nothing was written to production?range=30d, and 1 filter offers 33 add-links while 2 filters offer 0 (chart targets[null,null]). Two-filter page checked visually.After merge
Check the Deploy job, not just this PR's checkmark. Then confirm in production:
robots.txt, the 403 for a bot UA,X-Beam-Cache: HITon a repeat request, and dailyrowsReadin D1 analytics falling over the next few days.🤖 Generated with Claude Code