refactor(core): dedup the V1/V2 list-XML builders#72
Merged
Conversation
build_list_xml and build_list_xml_v1 were ~95% identical — directory-marker filtering, key/prefix rewriting, and URL-encoding were copy-pasted in full, with the two functions differing only in their pagination fields (key_count / continuation tokens for V2, marker / next_marker for V1). Extract the version-agnostic work into collect_list_entries (returning a ListEntries struct) and the S3 RFC-3986 encoding into a free s3_encode helper. Each builder now just calls the helper and fills in its own struct literal. URL-encoding folds into key/prefix construction, dropping the separate std::mem::take pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
🚀 Latest commit deployed to https://multistore-proxy-pr-72.development-seed.workers.dev
|
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.
What I'm changing
build_list_xmlandbuild_list_xml_v1incrates/core/src/api/list.rswere ~95% identical — the directory-marker filtering, key/prefix rewriting, and URL-encoding logic was copy-pasted in full across both functions. The only real difference is the pagination fields each emits (key_count+ continuation tokens for V2,marker+next_markerfor V1). Any fix to the shared logic (e.g. the directory-marker heuristic) had to be made in two places, and the duplication was the single biggest source of dead weight surfaced by a repo-wide over-engineering audit.How I did it
crates/core/src/api/list.rs— extracted the version-agnostic work into a newcollect_list_entriesfunction returning aListEntriesstruct (contents,common_prefixes, rawprefix_value,url_encodeflag). Both builders now call it and only fill in their own struct literal.s3_encode(s, url_encode)helper so it's defined once and reused for the per-version fields (prefix,delimiter,start_after).std::mem::takere-encode pass that existed in both functions.Net: 129 deletions / 97 insertions in the one file; behavior identical.
Test plan
cargo check -p multistorecargo clippy -p multistore(clean)cargo test -p multistore --lib api::list— 16 passed, 0 failedcargo fmt🤖 Generated with Claude Code