fix(editor): restrict query history autocomplete for performance COMPASS-8359#7928
fix(editor): restrict query history autocomplete for performance COMPASS-8359#7928
Conversation
|
Assigned |
There was a problem hiding this comment.
Pull request overview
This PR improves performance and reduces noise in the query-history autocomplete by precomputing matchable query shapes up-front and enforcing tighter limits on what’s considered for completion.
Changes:
- Limit the number of recent/favorite queries considered in the query bar (most recent 5 per category).
- Refactor query-history autocomplete to precompute simplified strings/fields once and cap results/fields/value-length for performance.
- Add tests covering new limits (max 10 suggestions, max value length 200, no nested-field matching).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/compass-query-bar/src/components/option-editor.tsx | Restricts option-based query history inputs to the most recent 5 items (per recent/favorite) before autocompletion. |
| packages/compass-editor/src/codemirror/query-history-autocompleter.ts | Prepares queries once, limits results/fields/value sizes, and changes matching logic to use prepared data. |
| packages/compass-editor/src/codemirror/query-autocompleter-with-history.test.ts | Adds/updates tests to validate the new autocomplete restrictions and behavior. |
| if (!query.queryProperties[propertyName]) { | ||
| return ''; | ||
| } | ||
|
|
||
| // The autocompletion uses a fuzzy search on the label, we only want to | ||
| // auto complete property that is being edited, not all of them. | ||
| return toJSString(query.queryProperties[propertyName]) || ''; |
There was a problem hiding this comment.
createQueryLabel treats falsy values (e.g. 0, empty string) as if the property is missing. This will produce an empty label for valid scalar query options like limit: 0, skip: 0, or maxTimeMS: 0. Consider checking for null/undefined (or using hasOwnProperty) instead of a falsy check so numeric zero values can still be labeled correctly.
| if (!query.queryProperties[propertyName]) { | |
| return ''; | |
| } | |
| // The autocompletion uses a fuzzy search on the label, we only want to | |
| // auto complete property that is being edited, not all of them. | |
| return toJSString(query.queryProperties[propertyName]) || ''; | |
| const value = query.queryProperties[propertyName]; | |
| if (value === undefined || value === null) { | |
| return ''; | |
| } | |
| // The autocompletion uses a fuzzy search on the label, we only want to | |
| // auto complete property that is being edited, not all of them. | |
| return toJSString(value) || ''; |
| .map((query) => { | ||
| const queryValue = query.queryProperties[queryProperty]; | ||
| // Only some query properties are objects. For instance sort can be an array. | ||
| const isObject = typeof queryValue === 'object'; | ||
|
|
||
| let scalarSimplified = ''; | ||
| let fields: PreparedField[] = []; | ||
|
|
||
| if (!queryValue) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
prepareQueries drops any query where the target property value is falsy (if (!queryValue) return null). This will incorrectly exclude valid scalar values like 0 for limit, skip, or maxTimeMS. Also, const isObject = typeof queryValue === 'object' treats arrays as objects, so array-valued properties will still be “field”-prepared via Object.entries(...), which conflicts with the stated goal of not autocompleting arrays. Consider (1) only excluding null/undefined values, and (2) explicitly skipping Array.isArray(queryValue) (or handling arrays separately) before running Object.entries.
COMPASS-8359
Adds some performance improvements to the historical autocomplete: