Skip to content

STIT-763 perf(api): return every filter option in one request and one query - #277

Merged
jdhoffa merged 11 commits into
mainfrom
feat/single-options-query
Sep 23, 2026
Merged

jdhoffa merged 11 commits into
mainfrom
feat/single-options-query

Conversation

@mbarlow12

@mbarlow12 mbarlow12 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Six filter dropdowns each called GET /oil-gas-fields/filter-options?field=X. One page load, six requests, each rebuilding the same large join. Now one request, one query.

  • db/queries.py — new filter_option_rows. The ranking window already groups by (resource_id, colname), so one pass picks the winner for every field. DISTINCT is over the (field, value) pair.
  • entities.py — OGFieldFilterOptionsResponse lists the six fields. FILTER_OPTION_FIELDS is derived from it, so the model and the query cannot drift.
  • db/og_field_resource_actions.py — filter_options takes no params and returns the model.
  • routers/oil_gas_fields.py — route takes no query parameters. field is gone. source is gone; it was already ignored.
  • components/FilterBar.jsx — one hook call, not one per dropdown. FilterFieldDropdown deleted.

Response keys: basin, country, field_status, primary_hydrocarbon_group, region, state_province. Always present. A field with no values returns []. Licensing is unchanged.

Risk to review

  • The query no longer joins the resources table, so it no longer checks repointed_id IS NULL.
  • It relies on a merged-away resource having all memberships INACTIVE. We maintain that invariant in code but not at the db level.
  • Follow-up ticket drafted to add the constraint to the db STIT-773

Conflicts with #275

  • STIT-746 fix(frontend): alphabetize country filter options #275 (STIT-746) changes the same two frontend files.
  • It adds a sort by display label inside FilterFieldDropdown, which this PR deletes.
  • Whoever merges second: put that sort in the new FILTER_FIELDS.map, and update the useResourceFilterOptions mock in ResourcesView.test.jsx to the new response shape.

Checks

Local Postgres via make dev-docker, seeded by ETL runs for gem, wm, ccr, alb and bc, plus a corpus of merges, reprioritizations, and llm generated content. >20k top level resources, ~58k source rows.

  • Same values. Dumped existing results for all six fields before deleting the old code, for all license sets a real user can hold. New code returns identical values for all five. The five differ from each other, so the comparison means something.
  • Six requests down to one. Loaded the page in a browser. One /filter-options request, no query string. All six dropdowns fill. Filtering still returns rows (34,036 to 16,563 on "Producing").
  • One query. With LOG_ALL_QUERIES=true the route logs db_query_count=2: the shared get_current_user lookup at 1ms, and the options query at 181ms. One query for the route's own work.
  • Tests. 272 API tests and 354 frontend tests pass. make check passes.

Covering tests: TestResourceFilterOptionsAction (tests/db/test_resource_actions.py), TestGetResourceFilterOptionsUnit (tests/routers/test_resources_unit.py), and ResourcesView.test.jsx, api.test.js, resources.test.js.

AI Usage

  • Spike design and implementation created with heavy oversight (see DNM: spike scripts for STIT-763 #278). Focused on narrow scope & minimal implementation.
  • Once the spike was complete and confirmed, AI led planning & implementation went fairly smoothly

- replace the per-field /filter-options contract with an all-fields
  response keyed by field name; drop the field and source params
- add queries.filter_option_rows: one ROW_NUMBER pass over
  (resource_id, colname) answers all six fields, DISTINCT over the pair
- derive the filterable field list from OGFieldFilterOptionsResponse so
  the model and the query cannot drift
- FilterBar calls the options hook once instead of once per dropdown
- values verified identical to the previous implementation for every
  licence profile before the old code was removed
Includes drift that predates this branch: new source types, the removed
merge-candidate preview endpoint, the added field-priority endpoint, and
requested_resource_id. Only the filter-options section is from STIT-763.
@github-actions

Copy link
Copy Markdown

CD summary ce54ec5

Frontend: https://witty-mushroom-017a3dc1e-277.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0277-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-0277-el.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-277.westus2.1.azurestaticapps.net
stitch-llm open pr-0277-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0277 stitch-dev.postgres.database.azure.com 5432 pr_0277
Jobs (2)
job image postgres_db api_url auth_mode
db-migrations ghcr.io/rmi/stitch-api:pr-0277@sha256:8f1095d13b615d1ed735743a1cd0c838cb18196d9f59a56f54520f45785bfd3f pr_0277
seed ghcr.io/rmi/stitch-seed:pr-0277@sha256:803dd0e0e88c72ae9529e0663a90e42712c8609b3890fcf08248fabf7d5bb3c4 https://pr-0277-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io/api/v1 stitch-client-bearer-token
Images (4)
build_time commit_time git_sha image image_digest
2026-09-16T23:42:26Z 2026-09-16T23:42:08Z 7b5fc34 ghcr.io/rmi/stitch-api:pr-0277 ghcr.io/rmi/stitch-api:pr-0277@sha256:8f1095d13b615d1ed735743a1cd0c838cb18196d9f59a56f54520f45785bfd3f
2026-09-16T23:42:26Z 2026-09-16T23:42:08Z 7b5fc34 ghcr.io/rmi/stitch-entity-linkage:pr-0277 ghcr.io/rmi/stitch-entity-linkage:pr-0277@sha256:47ccfb12b48bb831f2fa516829a6d1c1fc2543af71d4b9613805904b2a8079f3
2026-09-16T23:42:24Z 2026-09-16T23:42:08Z 7b5fc34 ghcr.io/rmi/stitch-seed:pr-0277 ghcr.io/rmi/stitch-seed:pr-0277@sha256:803dd0e0e88c72ae9529e0663a90e42712c8609b3890fcf08248fabf7d5bb3c4
2026-09-16T23:42:22Z 2026-09-16T23:42:08Z 7b5fc34 ghcr.io/rmi/stitch-stitch-llm:pr-0277 ghcr.io/rmi/stitch-stitch-llm:pr-0277@sha256:a4c5e892c8a746cf38361b566269e5aa7ef657b720e9d6ca25d6fc2f74e525d1

@mbarlow12
mbarlow12 marked this pull request as ready for review September 17, 2026 00:14
@github-actions

Copy link
Copy Markdown

CD summary 84b0aec

Frontend: https://witty-mushroom-017a3dc1e-277.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0277-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-0277-el.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-277.westus2.1.azurestaticapps.net
stitch-llm open pr-0277-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0277 stitch-dev.postgres.database.azure.com 5432 pr_0277
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-0277@sha256:d79b1202bdcf1439b4ca1533a8b9caa443e33344c4a65bb04559b064db6a14b9 pr_0277
Images (4)
build_time commit_time git_sha image image_digest
2026-09-21T19:11:30Z 2026-09-21T19:11:09Z a2e6f74 ghcr.io/rmi/stitch-api:pr-0277 ghcr.io/rmi/stitch-api:pr-0277@sha256:d79b1202bdcf1439b4ca1533a8b9caa443e33344c4a65bb04559b064db6a14b9
2026-09-21T19:11:25Z 2026-09-21T19:11:09Z a2e6f74 ghcr.io/rmi/stitch-entity-linkage:pr-0277 ghcr.io/rmi/stitch-entity-linkage:pr-0277@sha256:8a98817dd6459000c49128c41252331a9e440dc9fbb5f131277d7f3834521ea4
2026-09-21T19:11:25Z 2026-09-21T19:11:09Z a2e6f74 ghcr.io/rmi/stitch-seed:pr-0277 ghcr.io/rmi/stitch-seed:pr-0277@sha256:c39b212ae90296c00aa5a964a8b8bad41b5c719b1b4d334347e8cbe086a589d1
2026-09-21T19:11:32Z 2026-09-21T19:11:09Z a2e6f74 ghcr.io/rmi/stitch-stitch-llm:pr-0277 ghcr.io/rmi/stitch-stitch-llm:pr-0277@sha256:7e0fa38635ebfafd732f2d211d0f0a44ed3cfdaca49cefddd1d9b00dead2ae2f

- Merging #275 kept `FilterFieldDropdown`, which nothing referenced after
  this branch moved to a single filter-options query.
- Its sort by display label (STIT-746) was the only copy, so deleting the
  dead wrapper would have dropped country ordering; moved it into the
  `FILTER_FIELDS.map` instead.
- Updated the alphabetical-order test to mock the new keyed response shape
  rather than the old per-field `{ field, values }`.
@github-actions

Copy link
Copy Markdown

CD summary 70d6e93

Deployments (1)
service url fqdn
api open pr-0277-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0277 stitch-dev.postgres.database.azure.com 5432 pr_0277
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-0277@sha256:089cfda22b16cea7161e3a8701e5b9f7173d96db64bef243c48ffcbaa67a1816 pr_0277
Images (4)
build_time commit_time git_sha image image_digest
2026-09-23T04:26:36Z 2026-09-23T04:26:23Z 1e00256 ghcr.io/rmi/stitch-api:pr-0277 ghcr.io/rmi/stitch-api:pr-0277@sha256:089cfda22b16cea7161e3a8701e5b9f7173d96db64bef243c48ffcbaa67a1816
2026-09-23T04:26:38Z 2026-09-23T04:26:23Z 1e00256 ghcr.io/rmi/stitch-entity-linkage:pr-0277 ghcr.io/rmi/stitch-entity-linkage:pr-0277@sha256:bbbd33f6bc2dd9df2e6e25ae2c729cd3e6506d2d9dc0a47f92740d3687bee781
2026-09-23T04:26:41Z 2026-09-23T04:26:23Z 1e00256 ghcr.io/rmi/stitch-seed:pr-0277 ghcr.io/rmi/stitch-seed:pr-0277@sha256:8a70d87091ac67267e54b8c3c97bac6699dbac7083b492000f01f021a1bba4b6
2026-09-23T04:26:36Z 2026-09-23T04:26:23Z 1e00256 ghcr.io/rmi/stitch-stitch-llm:pr-0277 ghcr.io/rmi/stitch-stitch-llm:pr-0277@sha256:b6116b0dd47e03355ef5815698cea1f8fbddedd80426b5bf1911250c332e8ac0

@github-actions

Copy link
Copy Markdown

CD summary e5652da

Database (1)
db_name postgres_host postgres_port postgres_db
pr_0277 stitch-dev.postgres.database.azure.com 5432 pr_0277
Images (4)
build_time commit_time git_sha image image_digest
2026-09-23T04:29:24Z 2026-09-23T04:28:08Z df535e7 ghcr.io/rmi/stitch-api:pr-0277 ghcr.io/rmi/stitch-api:pr-0277@sha256:d52f4860d24b6b24d0b19be97cb10c9eaa65157e52bb5f458d7109f65760e347
2026-09-23T04:29:24Z 2026-09-23T04:28:08Z df535e7 ghcr.io/rmi/stitch-entity-linkage:pr-0277 ghcr.io/rmi/stitch-entity-linkage:pr-0277@sha256:7299d78b79aab93cc9c3a62e022fd6d0b0bdfcdbfea1f344948224aebc0c2323
2026-09-23T04:29:23Z 2026-09-23T04:28:08Z df535e7 ghcr.io/rmi/stitch-seed:pr-0277 ghcr.io/rmi/stitch-seed:pr-0277@sha256:96cc77f210a5a3d867c0bf97caf4f1f11c8e029c344f6c5d897d25a99ead5aae
2026-09-23T04:29:27Z 2026-09-23T04:28:08Z df535e7 ghcr.io/rmi/stitch-stitch-llm:pr-0277 ghcr.io/rmi/stitch-stitch-llm:pr-0277@sha256:8c641e881525270d52acf884ad5fe1839108522c7ce39869160bf6962a1c5f6a

@github-actions

Copy link
Copy Markdown

CD summary 5c9ac2b

Frontend: https://witty-mushroom-017a3dc1e-277.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0277-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-0277-el.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-277.westus2.1.azurestaticapps.net
stitch-llm open pr-0277-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0277 stitch-dev.postgres.database.azure.com 5432 pr_0277
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-0277@sha256:1bdce6cd81d1ba00e6accf60b08b4014655a99584c4d6945087bd7113603cffa pr_0277
Images (4)
build_time commit_time git_sha image image_digest
2026-09-23T04:30:43Z 2026-09-23T04:30:20Z 0a01e86 ghcr.io/rmi/stitch-api:pr-0277 ghcr.io/rmi/stitch-api:pr-0277@sha256:1bdce6cd81d1ba00e6accf60b08b4014655a99584c4d6945087bd7113603cffa
2026-09-23T04:30:45Z 2026-09-23T04:30:20Z 0a01e86 ghcr.io/rmi/stitch-entity-linkage:pr-0277 ghcr.io/rmi/stitch-entity-linkage:pr-0277@sha256:4190472c6f8bd10dc4b50bfc1bb10a64d0ce3721d78d5bdc29b1c795867a9cb6
2026-09-23T04:30:43Z 2026-09-23T04:30:20Z 0a01e86 ghcr.io/rmi/stitch-seed:pr-0277 ghcr.io/rmi/stitch-seed:pr-0277@sha256:db76473f447ca13d0492c8af8dfea484acb0209c8bf575ae8468940ff7918391
2026-09-23T04:30:43Z 2026-09-23T04:30:20Z 0a01e86 ghcr.io/rmi/stitch-stitch-llm:pr-0277 ghcr.io/rmi/stitch-stitch-llm:pr-0277@sha256:8f480fb2ebbbe2bab04a6d126dd6148b6ff95aab140722180b02aac30fc92304

@AlexAxthelm AlexAxthelm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! much cleaner!

@jdhoffa
jdhoffa merged commit 8791de4 into main Sep 23, 2026
32 checks passed
@jdhoffa
jdhoffa deleted the feat/single-options-query branch September 23, 2026 15:38
@jdhoffa
jdhoffa deployed to development September 23, 2026 15:38 — with GitHub Actions Active
@jdhoffa
jdhoffa deployed to development September 23, 2026 15:38 — with GitHub Actions Active
@jdhoffa
jdhoffa deployed to development September 23, 2026 15:38 — with GitHub Actions Active
@jdhoffa
jdhoffa deployed to development September 23, 2026 15:38 — with GitHub Actions Active
@jdhoffa
jdhoffa deployed to development September 23, 2026 15:38 — with GitHub Actions Active
@jdhoffa
jdhoffa deployed to development September 23, 2026 15:38 — with GitHub Actions Active
@AlexAxthelm AlexAxthelm mentioned this pull request Sep 24, 2026
4 tasks done

This branch was successfully deployed

1 active deployment
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.

3 participants