Skip to content

refactor: percent-encode cache key subject instead of hex#160

Open
alukach wants to merge 1 commit into
mainfrom
refactor/cache-key-percent-encode
Open

refactor: percent-encode cache key subject instead of hex#160
alukach wants to merge 1 commit into
mainfrom
refactor/cache-key-percent-encode

Conversation

@alukach

@alukach alukach commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

What

cache_key_with_subject hand-rolled hex encoding (subj.bytes().map(|b| format!("{:02x}", b))) to make the subject URL-safe in the cache key. The percent_encoding crate — already imported in this file, with a PATH_SEGMENT set already defined — does the same job.

let encoded = utf8_percent_encode(subj, PATH_SEGMENT);

Why

Same guarantee (injective, URL-safe), no hand-rolled encoder, and shorter keys (only non-unreserved bytes get expanded, vs. every byte → 2 hex chars). Reuses tooling the file already pulls in rather than reimplementing it.

Verification

cargo clippy --target wasm32-unknown-unknown clean; full pre-push suite green. utf8_percent_encode returns a Display type so the format! key construction is unchanged.

Found via ponytail over-engineering audit.

🤖 Generated with Claude Code

cache_key_with_subject hand-rolled hex encoding to make the subject
URL-safe. percent_encoding (utf8_percent_encode + PATH_SEGMENT) is
already imported in this file and gives the same injective, URL-safe
guarantee with shorter keys. Reuse it instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Claude finished @alukach's task in 22s —— View job


✅ No blocking issues — safe to merge.

  • src/cache.rs:121utf8_percent_encode with PATH_SEGMENT is a correct drop-in replacement for the hand-rolled hex encoder. Both are injective and URL-safe; the only observable difference is shorter keys for typical ASCII subjects (e.g. a UUID subject passes through unchanged vs. being doubled in length by hex). The Display impl on PercentEncode means format!("{api_url}{sep}subject={encoded}") on line 127 works identically to before.

  • The PATH_SEGMENT set (lines 16–20) already encodes % itself (it's in NON_ALPHANUMERIC), so percent-encoded output is round-trip safe — a subject containing a literal % won't be misread as an already-encoded sequence.

  • Cache keys generated before this change (hex) and after (percent-encoded) are not compatible, so any cached entries at deploy time will miss and be rehydrated. That's benign given the short TTLs (60–1800 s) and the fact this is a read-through cache.

@github-actions

Copy link
Copy Markdown

🚀 Latest commit deployed to https://source-data-proxy-pr-160.source-coop.workers.dev

  • Date: 2026-06-18T23:38:30Z
  • Commit: 774aaf5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant