Skip to content

fix(editor): restrict query history autocomplete for performance COMPASS-8359#7928

Open
Anemy wants to merge 2 commits intomainfrom
COMPASS-8359-historical-query-autocomplete
Open

fix(editor): restrict query history autocomplete for performance COMPASS-8359#7928
Anemy wants to merge 2 commits intomainfrom
COMPASS-8359-historical-query-autocomplete

Conversation

@Anemy
Copy link
Copy Markdown
Member

@Anemy Anemy commented Mar 30, 2026

COMPASS-8359

Adds some performance improvements to the historical autocomplete:

  • Restricts the amount of suggestions to 10.
  • Computes the saved queries to match at the creation of the autocomplete (rather than on type). This'll speed up the autocomplete on type, at the expensive of a bit more compute up front. We're a bit better at avoiding looping through things we know won't match now as well.
  • Prevents autocompleting more than 10 fields (was 30 previously).
  • Prevents autocompleting fields that, when stringified, are longer that 200 characters.
  • Prevents autocompleting in arrays and nested objects. Most of the time we want this to complete on the field name so we can give fewer suggestions at the benefit of performance here.

@Anemy Anemy requested a review from a team as a code owner March 30, 2026 23:15
@Anemy Anemy requested review from Copilot and nbbeeken March 30, 2026 23:15
@github-actions github-actions bot added the fix label Mar 30, 2026
@codeowners-service-app codeowners-service-app bot requested a review from gagik March 30, 2026 23:16
@codeowners-service-app
Copy link
Copy Markdown

Assigned gagik for team compass-developers because nbbeeken is out of office.

@Anemy Anemy changed the title fix(editor): restrict historical autocomplete for performance COMPASS-8359 fix(editor): restrict query history autocomplete for performance COMPASS-8359 Mar 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +59 to +65
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]) || '';
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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) || '';

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +100
.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;
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants