Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit autobatching #3216

Open
rahul1 opened this issue Nov 3, 2023 · 1 comment
Open

Explicit autobatching #3216

rahul1 opened this issue Nov 3, 2023 · 1 comment
Labels
fhir-datastore Related to the FHIR datastore, includes API and FHIR operations

Comments

@rahul1
Copy link
Member

rahul1 commented Nov 3, 2023

Background

Right now, Medplum supports time-based autobatching. This works great for front-end applications. For backend / server applications, developers have asked for more control over which requests are part of a batch request.

Proposal

add a startBatch() and endBatch() method to the MedplumClient, to be used as follows:

medplum.startBatch()
const patients = await Promise.all([ 
    medplum.readResource('Patient', '1'),
    medplum.readResource('Patient', '2'),
    medplum.readResource('Patient', '3'),
])
medplum.endBatch()
@rahul1 rahul1 added the fhir-datastore Related to the FHIR datastore, includes API and FHIR operations label Nov 3, 2023
@rahul1 rahul1 added this to the Milestone Quality milestone Nov 3, 2023
@dillonstreator
Copy link
Contributor

@rahul1 how is this intended to work in the following example?

async function doThing() {
  medplum.startBatch()
  const patients = await Promise.all([ 
      medplum.readResource('Patient', '1'),
      medplum.readResource('Patient', '2'),
      medplum.readResource('Patient', '3'),
  ])
  medplum.endBatch()
}

doThing()
doThing()

Would subsequent startBatch() calls prior to an endBatch() call block until endBatch() is called?

Maybe a batch identifier could be provided or the startBatch call could return an identifier?

async function doThing(batchIdentifier: string) {
  medplum.startBatch(batchIdentifier)
  const patients = await Promise.all([ 
      medplum.readResource('Patient', '1', { batchIdentifier }),
      medplum.readResource('Patient', '2', { batchIdentifier }),
      medplum.readResource('Patient', '3', { batchIdentifier }),
  ])
  medplum.endBatch(batchIdentifier)
}

doThing("1")
doThing("2")
doThing("1") // This could block until the first call to `doThing("1")` finishes its batch. Ideally, unique batch ids would be provided so this shouldn't be encountered but this behavior would need to be documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fhir-datastore Related to the FHIR datastore, includes API and FHIR operations
Projects
Status: No status
Development

No branches or pull requests

2 participants