Improve tree search efficiency#7941
Conversation
| import { tables } from '../../DataModel/tables'; | ||
| import { queryFieldFilterSpecs } from '../../QueryBuilder/FieldFilterSpec'; | ||
| import { makeComboBoxQuery } from '../helpers'; | ||
| import { QUERY_COMBO_BOX_SEARCH_LIMIT } from '../index'; |
There was a problem hiding this comment.
This isn't included in this PR
grantfitzsimmons
left a comment
There was a problem hiding this comment.
Testing instructions
- Open a form with a tree-based QueryComboBox (e.g., Taxon field on a Determination)
- Type a few characters and verify the typeahead dropdown populates quickly
- Check user preferences -- the tree search algorithm should now default to "starts with"
- Run the frontend tests:
npx jest --testPathPattern treeSearchEfficiency
This is pretty simple, just changing the default preference, but it does speed up searches. The automatic test is not passing, however.
e15b0f4 to
d0e2aa3
Compare
|
Fixed —
All 3 tests pass locally: |
|
|
||
| // Typeahead dropdown doesn't need 1000 results — 50 is more than enough. | ||
| // Reducing this from 1000 also cuts the DB query cost significantly. | ||
| export const QUERY_COMBO_BOX_SEARCH_LIMIT = 50; |
There was a problem hiding this comment.
I'd prefer that we fetch query combo box results in batches on scroll rather than limiting it to 50
Change default tree search algorithm from 'contains' (LIKE '%x%') to 'startsWith' (LIKE 'x%'), enabling B-tree index usage on 200K+ row tree tables. Replace hardcoded limit of 1000 with paginated batch-on-scroll loading: - Initial fetch returns first 50 results (QUERY_COMBO_BOX_PAGE_SIZE) - Scrolling near the bottom of the dropdown fetches the next 50 - Loading indicator shown while fetching more results - Continues until all results are loaded Changes: - UserDefinitions.tsx: default treeSearchAlgorithm 'contains' -> 'startsWith' - QueryComboBox/index.tsx: paginated fetchSource with handleScrollEnd - AutoComplete.tsx: onScrollEnd, isLoadingMore, extraItems props - treeSearchEfficiency.test.tsx: verify default operator and page size
d0e2aa3 to
57ac51a
Compare
|
Updated per feedback — replaced the hard limit of 50 with batch-on-scroll pagination:
The All 12 tests across AutoComplete + QueryComboBox suites pass. |
|
Moved to this PR with additional fixes #8016 |
Fixes #7752
Contributed by @foozleface
Tree search in QueryComboBox sends a LIKE query per keystroke. On tree tables with 200K+ rows, using "contains" mode generates
LIKE '%pattern%'which cannot use B-tree indexes and causes full table scans. This PR changes the default search mode from "contains" to "startsWith", enablingLIKE 'pattern%'which uses B-tree indexes. It also reduces the search result limit from 1000 to 50, since a typeahead dropdown never needs that many results.Implementation
treeSearchAlgorithmuser preference fromcontainstostartsWithinUserDefinitions.tsxQUERY_COMBO_BOX_SEARCH_LIMITconstant set to 50 (was 1000)Testing instructions
npx jest --testPathPattern treeSearchEfficiency