Skip to content

Comments

Improve performance of Organization endpoint#395

Merged
spopelka-dsac merged 7 commits intomainfrom
sjp/org-endpoint-improvements
Feb 11, 2026
Merged

Improve performance of Organization endpoint#395
spopelka-dsac merged 7 commits intomainfrom
sjp/org-endpoint-improvements

Conversation

@spopelka-dsac
Copy link
Contributor

@spopelka-dsac spopelka-dsac commented Feb 10, 2026

module-name: Improve performance of Organization endpoint

Jira Ticket #NDH-795

Problem

The Organization endpoint was not optimized for performance and was quite slow to query.

Solution

  • Add a migration to create a search vector for organization name (the field that is likely to be used most often to query results), to create a materialized view that pre-populates the organization primary name annotation so it's not queried on the fly, and to create indexes on the search vector and primary name fields
  • Update models.py to reflect the new view and search vector fields
  • Update views.py to query the organization view instead of the organization table
  • Update filters and serializers as needed
  • Update tests to reflect the new sort field name ("name")
  • Update front end code to reflect the new sort field name ("name")

Result

Organization queries that once took ~20 seconds now take seconds

Here is a screenshot showing 1.6 seconds across the full 3+ million organization Halloween dataset.
image

Test Plan

  1. All tests should pass
  2. Run make up from root
  3. Query the Organization endpoint (e.g. https://localhost:8000/fhir/Organization)

Note: The view logic is a big complex to account for the potential of multiple and/or no organization names listed as being primary, due to the fact that the organization name data we currently have does not specify which organization names are primary. We will likely be able to clean it up in the future, with a better understanding of what the shape of the data will look like in a post-Halloween CSV world.

Credit where credit is due: this PR builds off the work that Adam started in #283

@spopelka-dsac spopelka-dsac merged commit ca5072e into main Feb 11, 2026
12 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.

2 participants