feat(billing-platform): add batched ChargeService.list_charges_for_invoice_ids (REVENG-157)#312
Closed
armcknight wants to merge 2 commits into
Closed
feat(billing-platform): add batched ChargeService.list_charges_for_invoice_ids (REVENG-157)#312armcknight wants to merge 2 commits into
armcknight wants to merge 2 commits into
Conversation
|
The latest Buf updates on your PR. Results from workflow ci / buf-checks (pull_request).
|
…voice_ids (REVENG-157) Adds a batched endpoint that returns ``PlatformCharge`` (the canonical projection, with refunds embedded via ``PlatformCharge.refunds`` from sentry-protos#303) for every charge tied to any of a list of invoices. Avoids the N+1 of fetching refunds (or charges) per invoice when rendering paginated invoice lists. - **`services/charge/v1/endpoint_list_charges.proto`** — new ``ListChargesForInvoiceIdsRequest`` (``repeated uint64 invoice_ids``) + ``ListChargesForInvoiceIdsResponse`` (flat list of ``PlatformCharge`` ordered by ``(invoice_id, date_added)``). The singleton ``ListChargesForInvoiceRequest`` / ``Charge`` slim type in the same file is left as-is for now (currently unused; deferring deprecation to a separate proto-policy follow-up). Picked the charges-with-embedded-refunds shape over a separate ``list_refunds_by_invoice_ids`` because it leverages the existing ``PlatformCharge.refunds`` field and sets up admin invoice surfaces that want full charge + refund detail in one round trip. Consumers that only need refund totals (e.g. customer invoice list) still get what they need by summing ``charge.refunds[*].amount_cents`` grouped by ``charge.invoice_id``. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
9264e07 to
280e77c
Compare
Member
Author
|
Closing — switching the batch shape to a dataclass prototype on the getsentry side (per the billing-platform CLAUDE.md prototyping convention). We'll solidify the wire contract here after the design has been validated in production. The current PlatformCharge.refunds field (from #303) is sufficient for the dataclass implementation. |
auto-merge was automatically disabled
June 16, 2026 17:44
Pull request was closed
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
Adds a batched endpoint that returns
PlatformCharge(the canonical projection, with refunds embedded viaPlatformCharge.refundsfrom #303) for every charge tied to any of a list of invoices.services/charge/v1/endpoint_list_charges.proto— newListChargesForInvoiceIdsRequest(repeated uint64 invoice_ids) +ListChargesForInvoiceIdsResponse(flat list ofPlatformChargeordered by(invoice_id, date_added)).Why
getsentry#20613 hit a Cursor-bot-flagged N+1 in the customer invoices list — paginated rendering was calling
ChargeService.list_refunds_by_invoiceonce per invoice. Earlier review feedback from Noah (getsentry#20611 thread) pointed at the same pattern: derive aggregates from per-row data, batch where possible.This PR went with charges-with-embedded-refunds rather than a separate
list_refunds_by_invoice_idsbecause:PlatformCharge.refundsalready exists (added in feat(billing-platform): add refund types + record_charge_refunds endpoint (REVENG-157) #303); we just need a batch method that populates and returns it.charge.refunds[*].amount_centsgrouped bycharge.invoice_id.The singleton
ListChargesForInvoiceRequest/ slimChargetype in the same file (dormant, defined in #211 but never implemented) is left as-is — deferring its deprecation to a separate proto-policy follow-up.Test plan
buf breakingpasses (verified locally — additive only)_PlatformInvoiceSourceto eliminate the N+1🤖 Generated with Claude Code