Skip to content

Add Repository.queryBatched with structural query-key batching and projection-safe decoding#765

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/optimize-parallel-queries
Draft

Add Repository.queryBatched with structural query-key batching and projection-safe decoding#765
Copilot wants to merge 5 commits into
mainfrom
copilot/optimize-parallel-queries

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 23, 2026

This change adds a full batched-query path for repository reads, including structural query-key comparison so equivalent filters (including array operands like in) coalesce reliably. It also keeps decoding behavior projection-safe by resolving each projection independently from a shared fetched row set.

  • Problem addressed

    • Introduces a concrete end-to-end implementation of batched repository querying.
    • Ensures batch grouping is structural (not reference/order fragile), including filters with array values.
  • Repository API surface

    • Added queryBatched to Repository (queryBatched: this["query"]) so it mirrors existing query typing/usage.
  • Batching internals

    • Added grouped request-based batching in repository internals.
    • Implemented structural canonicalization for batch keys over:
      • mode / result type
      • filter / order
      • limit / skip
      • fixed (non-mergeable) select items
    • Merges plain projection select fields across compatible requests in the same batch.
  • Decode/projection behavior

    • Executes one shared store filter call per batch group.
    • Applies per-request decode/projection resolution on the shared row set to avoid unsafe cross-projection transform assumptions.
  • Coverage

    • Added test coverage for concurrent queryBatched calls using in filters with array values and different projections.
    • Added a changeset for @effect-app/infra.
const cartIds = ["cart-1", "cart-2"]

const [a, b] = yield* Effect.all([
  repo.queryBatched(
    where("cartId", "in", cartIds),
    project(S.Struct({ id: S.String, cartId: S.String }))
  ),
  repo.queryBatched(
    where("cartId", "in", cartIds),
    project(S.Struct({ id: S.String, qty: S.Number }))
  )
])

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 23, 2026

Open in StackBlitz

@effect-app/cli

npm i https://pkg.pr.new/effect-app/libs/@effect-app/cli@765

effect-app

npm i https://pkg.pr.new/effect-app/libs/effect-app@765

@effect-app/eslint-codegen-model

npm i https://pkg.pr.new/effect-app/libs/@effect-app/eslint-codegen-model@765

@effect-app/eslint-shared-config

npm i https://pkg.pr.new/effect-app/libs/@effect-app/eslint-shared-config@765

@effect-app/infra

npm i https://pkg.pr.new/effect-app/libs/@effect-app/infra@765

@effect-app/vue

npm i https://pkg.pr.new/effect-app/libs/@effect-app/vue@765

@effect-app/vue-components

npm i https://pkg.pr.new/effect-app/libs/@effect-app/vue-components@765

commit: 20cce98

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.

2 participants