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

Gather and validate all resource references at one time #5496

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

mattwiller
Copy link
Member

No description provided.

@mattwiller mattwiller added the fhir-datastore Related to the FHIR datastore, includes API and FHIR operations label Nov 5, 2024
@mattwiller mattwiller added this to the November 30, 2024 milestone Nov 5, 2024
@mattwiller mattwiller self-assigned this Nov 5, 2024
@mattwiller mattwiller requested a review from a team as a code owner November 5, 2024 01:03
Copy link

vercel bot commented Nov 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medplum-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 6:23pm
medplum-provider ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 6:23pm
medplum-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 6:23pm
medplum-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 6:23pm

Copy link
Member

@ThatOneBro ThatOneBro left a comment

Choose a reason for hiding this comment

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

Looks good! Hoping to see some wins from this. Let's put this on staging first just for sanity check?

} catch (err) {
issues.push(createStructureIssue(path, `Invalid reference (${normalizeErrorString(err)})`));
const validated = await repo.readReferences(toValidate);
for (let i = 0; i < validated.length; i ) {
Copy link
Member

Choose a reason for hiding this comment

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

I love numeric for loops 👍

const validated = await repo.readReferences(toValidate);
for (let i = 0; i < validated.length; i ) {
const reference = validated[i];
if (reference instanceof Error) {
Copy link
Member

@ThatOneBro ThatOneBro Nov 5, 2024

Choose a reason for hiding this comment

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

instanceof in a hot loop is not great, I wish we had a tagged union or something (eg. Option type), but alas.

It's obviously the right choice here just making a note

Copy link
Member Author

Choose a reason for hiding this comment

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

@ThatOneBro Is there anything else we should consider here? Would inverting the condition by calling e.g. isResource() instead be better?

Copy link
Member

Choose a reason for hiding this comment

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

Actually it could improve things slightly, worth a try

Copy link
Member Author

Choose a reason for hiding this comment

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

We ran a microbenchmark on both approaches, and discovered that for this use case instanceof Error is about 10x faster than isResource()

Copy link

sonarqubecloud bot commented Nov 5, 2024

@mattwiller mattwiller added this pull request to the merge queue Nov 6, 2024
Merged via the queue into main with commit bc98343 Nov 6, 2024
32 checks passed
@mattwiller mattwiller deleted the check-references-tx-err branch November 6, 2024 18:19
@codyebberson codyebberson restored the check-references-tx-err branch November 7, 2024 04:10
codyebberson added a commit that referenced this pull request Nov 7, 2024
codyebberson added a commit that referenced this pull request Nov 7, 2024
medplumbot added a commit that referenced this pull request Nov 8, 2024
## What's Changed

* Update deb-s3 upload command (#5494)
* More build-deb action fixes (#5497)
* Added GCP Secret Manager support and configType: gcp (#5462)
* Case-insensitive search on ContactPoint (#5455)
* Centralize token index type determination logic (#5500)
* Gather and validate all resource references at one time (#5496)
* Revert "Gather and validate all resource references at one time (#5496)" (#5504)
* Improve FHIR Datastore docs (#5484)
* Check all references at once (#5508)
* Fix QuestionnaireForm dependency on requestSchema (#5509)
* fix(agent): harden reconnect logic (#5476)
* Tighten up JSON vs FHIR JSON response formatting (#5506)

**Full Changelog**: v3.2.19...v3.2.20
github-merge-queue bot pushed a commit that referenced this pull request Nov 8, 2024
## What's Changed

* Update deb-s3 upload command (#5494)
* More build-deb action fixes (#5497)
* Added GCP Secret Manager support and configType: gcp (#5462)
* Case-insensitive search on ContactPoint (#5455)
* Centralize token index type determination logic (#5500)
* Gather and validate all resource references at one time (#5496)
* Revert "Gather and validate all resource references at one time (#5496)" (#5504)
* Improve FHIR Datastore docs (#5484)
* Check all references at once (#5508)
* Fix QuestionnaireForm dependency on requestSchema (#5509)
* fix(agent): harden reconnect logic (#5476)
* Tighten up JSON vs FHIR JSON response formatting (#5506)

**Full Changelog**: v3.2.19...v3.2.20
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: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants