Skip to content

refactor(core): dedup the V1/V2 list-XML builders#72

Merged
alukach merged 1 commit into
mainfrom
refactor/dedup-list-xml-builders
Jun 18, 2026
Merged

refactor(core): dedup the V1/V2 list-XML builders#72
alukach merged 1 commit into
mainfrom
refactor/dedup-list-xml-builders

Conversation

@alukach

@alukach alukach commented Jun 18, 2026

Copy link
Copy Markdown
Member

What I'm changing

build_list_xml and build_list_xml_v1 in crates/core/src/api/list.rs were ~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_marker for 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 new collect_list_entries function returning a ListEntries struct (contents, common_prefixes, raw prefix_value, url_encode flag). Both builders now call it and only fill in their own struct literal.
  • Pulled the S3 RFC-3986 URL-encoding closure out into a free s3_encode(s, url_encode) helper so it's defined once and reused for the per-version fields (prefix, delimiter, start_after).
  • Folded URL-encoding into key/prefix construction inside the iterator, dropping the separate std::mem::take re-encode pass that existed in both functions.

Net: 129 deletions / 97 insertions in the one file; behavior identical.

Test plan

  • cargo check -p multistore
  • cargo clippy -p multistore (clean)
  • cargo test -p multistore --lib api::list — 16 passed, 0 failed
  • cargo fmt

🤖 Generated with Claude Code

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>
@github-actions

Copy link
Copy Markdown

🚀 Latest commit deployed to https://multistore-proxy-pr-72.development-seed.workers.dev

  • Date: 2026-06-18T23:37:14Z
  • Commit: 13626e5

@alukach alukach merged commit 0a9cd12 into main Jun 18, 2026
12 checks passed
@alukach alukach deleted the refactor/dedup-list-xml-builders branch June 18, 2026 23:47
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