Repository navigation
Batch search related-data counts to reduce API query fan-out - #1677
christabone wants to merge 2 commits into
Conversation
|
Review summary The batching itself looks right. Keys are deduplicated, counts come back in input order through keyed One behavior change that could break production: a related-data count failure now fails the whole search
Unless failing the whole search is intended, consider catching the exception in Nothing else blocking. |
|
@claude Please review my changes. Commit b7faed6 addresses your availability finding: the DAO still rejects incomplete counts, while SearchService catches count-layer failures, logs them and returns the successful main results, totals and facets with empty calculated-link lists. Stored relatedData is preserved. Both service regressions and the full 25-test API/core suite pass; Astra medium approved this follow-up. Please inspect the updated diff and confirm whether any material issues remain. |
|
Claude finished @christabone's task in 37s —— View job Re-review after b7faed6
The availability finding from my earlier review is fixed in b7faed6. No material issues remain. What I checked in
Optional, non-blocking
Not verifiedI did not run the test suite or the Elasticsearch integration tests in this job. This review is based on reading the diff and the tests. Verdict: the earlier blocking finding is resolved, and nothing material remains. I have no objection to merging once the CI run (including the new Elasticsearch-backed test step) is green. |
|
We are going to achieve this a different way. |
The October 4 production investigation found a long search tail that bot rate limits alone cannot address. Four captured ten-minute CDN windows contained 55,146 API requests; 778 took at least five seconds, and 640 of those used
/api/search. Eleven model-search requests ended with CDN 504 OriginError after approximately 55 seconds. These counts describe the captured windows, rather than the entire weekend, and CDN duration is not identical to backend query time.A gene search filtered by
models=CX11321 (Cel)withlimit=50returned 200 after 50.826 seconds, almost entirely before the first byte. Inspection of the source retrieved from the running production API confirmed thatSearchServicethen enriches results sequentially: each gene without storedrelatedDatatriggers five synchronous Elasticsearch count searches, and each model triggers three. A bounded metadata-only lookup for that gene-search filter found 502 matching genes and returned 50; all 50 lackedrelatedData. Independent gene/model samples also lacked it. The fan-out therefore occurs on production data, rather than being only a theoretical code path.This PR removes that confirmed multiplier: a page of 50 genes goes from 250 additional count searches to five, and a page of 50 models goes from 150 to three. It also adds phase timings so subsequent observations can separate main-search latency from enrichment latency. The metadata lookup's 72 ms excluded API enrichment, facets, scoring and highlighting; it was not a replay or benchmark of the original request. Historical phase timings are unavailable, so the investigation does not establish how much of the 50.826 seconds came from counts, the main query or connection waiting.
Related-data predicates are deduplicated within each page and executed in sequential batches of at most 50 using named filters aggregations. The existing query builder, link order, labels, zero-count omission and precomputed metadata are preserved. Counts remain exact for overlapping multi-valued fields and totals above 10,000. The count layer rejects failed, timed-out or incomplete responses; the API preserves successful main-search results and facets, logs the enrichment failure and returns empty calculated-link lists while retaining stored metadata. It never presents partial counts as exact.
Slow searches (at least one second) and debug searches log total, main Elasticsearch and related-data durations, plus count-filter/request totals, to distinguish the remaining sources of latency.
Validation:
Production latency improvement still needs measurement. Main-query facet cost and the shared client's long snapshot-oriented timeouts remain separate follow-ups.
Requested review: @oblodgett.