Skip to content

refactor(llm-access-store): extract pure leaf helpers from postgres.rs (PR-A)#14

Merged
acking-you merged 1 commit into
masterfrom
refactor/split-store-postgres
May 31, 2026
Merged

refactor(llm-access-store): extract pure leaf helpers from postgres.rs (PR-A)#14
acking-you merged 1 commit into
masterfrom
refactor/split-store-postgres

Conversation

@acking-you
Copy link
Copy Markdown
Owner

What

First of two PRs splitting the ~10.3k-line llm-access-store/src/postgres.rs. This PR-A extracts only the pure free-function leaf layer into five focused submodules; the stateful PostgresControlRepository God-object (4.8k-line inherent impl + 16 trait impls) and all types stay in mod.rs for the follow-up domain split (PR-B).

postgres.rs is structurally unlike prior split targets (request.rs/cache_sim.rs/stream.rs/converter.rs/store.rs): its public God-object's inherent impl is a dense internal call-mesh, so splitting it by domain forces ~50 methods to pub(super). To keep each review small and de-risk incrementally, that work is deferred to PR-B. This PR-A is the zero-judgment, zero-pub(super) part.

New submodules (postgres/)

module contents
json optional-field JSON readers/writers + the decode_optional_json helper
decode PgRow → record / admin-view row decoders
codex_routing route quota scoring + cached auth-error derivation
proxy_support admin↔provider proxy transforms + legacy-proxy JSON cleanup
cache_convert control-record ↔ request-cache value conversions

mod.rs: 10336 → 9342 lines (1053 moved out).

Why zero visibility bumps

All types and the sqlx wrapper (PgRow/SqlxClient/SqlxTransaction) stay in mod.rs. Rust descendants can read ancestor-private items, so the moved submodules access them via use super::{...} with no field/method visibility changes. Moved free fns become pub only where referenced from a different region (mod-remaining / tests / a sibling submodule) — 45 became pub, 10 stayed private, the one private struct (CodexRouteQuotaScore) moved with its only callers.

Behavior-preserving

Structural move only — function bodies are byte-identical.

  • Identical top-level item inventory (verified by diff: 0 dropped, 0 added).
  • Same 10 #[test]/#[tokio::test] (the one pure unit test, aggregate_usage_rollup_deltas_merges_events, stays in mod.rs because its struct stays there too).

Verification

  • cargo clippy -p llm-access-store --all-targets -- -D warnings → clean
  • cargo test -p llm-access-store → 67 passed
  • cargo build -p llm-access (reverse dep) → ok
  • rustfmt on the 6 changed files only

🤖 Generated with Claude Code

Move the pure free-function leaf layer out of the ~10k-line postgres.rs
into five focused submodules, leaving the stateful PostgresControlRepository
God-object (inherent + 16 trait impls) and all types in mod.rs for a
follow-up domain split (PR-B).

- json: optional-field JSON readers/writers + the deserialize helper
- decode: PgRow -> record/admin-view row decoders
- codex_routing: route quota scoring + cached auth-error derivation
- proxy_support: admin<->provider proxy transforms + legacy JSON cleanup
- cache_convert: control-record <-> request-cache value conversions

Behavior-preserving structural move: identical top-level item inventory,
same 10 tests. Moved fns become `pub` only where referenced cross-region;
all types + the sqlx wrapper stay in mod.rs, so submodules read
ancestor-privates with zero pub(super)/pub(crate) bumps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@acking-you
Copy link
Copy Markdown
Owner Author

/gemini review

@acking-you
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors llm-access-store/src/postgres.rs by extracting numerous helper functions into smaller, domain-specific submodules: cache_convert, codex_routing, decode, json, and proxy_support. This change significantly improves code organization, readability, and maintainability. There are no review comments provided for this pull request, and the refactoring appears to be clean and correct.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the postgres module by extracting various helper functions from the large postgres.rs file into several dedicated submodules: cache_convert, codex_routing, decode, json, and proxy_support. This significantly improves code organization and maintainability. There are no review comments, and I have no feedback to provide.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@acking-you acking-you merged commit cffac33 into master May 31, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant