Repository navigation
feat(preview): limit cache-miss previews and retry empties sooner - #24
Merged
Merged
Conversation
Add a per-IP fixed-window limiter for /api/preview cache misses (20 per minute). Cached previews bypass it, so normal browsing stays unrestricted while a client cannot rapidly enumerate stored articles and burn the Workers AI / Browser Run quotas. The limiter uses the Cache API, is per-colo and fail-open, and returns 429 with Retry-After: 60 and reason "rate_limited". Empty no_content previews now cache for 5 minutes instead of 30 so a transient AI/Browser Run failure can retry. Add preview_rate_limited logging and cache_ttl_seconds on preview_empty. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
🔎 Cloudflare preview: https://671c4964-feedreader.phatpham9.workers.dev Uploaded from |
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.
Summary
/api/previewcache misses (20 per minute). Cached previews bypass it, so normal browsing stays unrestricted while a client cannot rapidly enumerate stored articles and burn Workers AI / Browser Run quota.429withreason: "rate_limited"andRetry-After: 60. It logspreview_rate_limited.no_contentpreviews now cache for 5 minutes instead of 30, so a transient AI/Browser Run failure can retry.preview_emptylogscache_ttl_seconds.previewRateLimit.ts/previewCachePolicy.ts.Verification
npm run typechecknpx vitest run --exclude '.claude/**'— 18 files, 145 testsnpm run db:migrate:localwrangler deploy --dry-run— 371.79 KiB / 98.61 KiB gzip200in 1.3s429in 9ms,reason: "rate_limited",preview_rate_limitedlogged200in 3.6ms, bypassing the limiter0 blocks → 300s,>0 blocks → 1800s.Notes
/api/personalizeis not included in this PR; it can get the same treatment separately.🤖 Generated with Claude Code