Skip to content

Commit f8370d2

Browse files
authored
feat(crud): do not apply default sort option for views and timeseries COMPASS-9749 (#7249)
* feat(crud): do not apply default sort option for views and timeseries COMPASS-9749 * chore(preferences): bolder font for not available
1 parent 4febfae commit f8370d2

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export type CrudStoreOptions = Pick<
269269
| 'namespace'
270270
| 'isTimeSeries'
271271
| 'isSearchIndexesSupported'
272+
| 'sourceName'
272273
> & {
273274
noRefreshOnConfigure?: boolean;
274275
};
@@ -1652,12 +1653,19 @@ class CrudStoreImpl
16521653
countOptions.hint = '_id_';
16531654
}
16541655

1656+
const isView = this.options.isReadonly && this.options.sourceName;
1657+
// Default sort options that we allow to choose from in settings will have a
1658+
// massive negative effect on the query performance for views and view-like
1659+
// collections in all cases. To avoid that, we're not applying default sort
1660+
// for those
1661+
const allowDefaultSort = !isView && !this.options.isTimeSeries;
1662+
1663+
const { defaultSortOrder } = this.preferences.getPreferences();
1664+
16551665
let sort = query.sort;
1656-
if (!sort && this.preferences.getPreferences().defaultSortOrder) {
1657-
sort = validate(
1658-
'sort',
1659-
this.preferences.getPreferences().defaultSortOrder
1660-
);
1666+
1667+
if (!sort && allowDefaultSort && defaultSortOrder) {
1668+
sort = validate('sort', defaultSortOrder);
16611669
}
16621670

16631671
const findOptions = {

packages/compass-preferences-model/src/preferences-schema.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ const enableDbAndCollStatsDescription: React.ReactNode = (
3737

3838
export const SORT_ORDER_VALUES = [
3939
'',
40-
'{ $natural: -1 }',
4140
'{ _id: 1 }',
4241
'{ _id: -1 }',
42+
'{ $natural: -1 }',
4343
] as const;
44+
4445
export type SORT_ORDERS = (typeof SORT_ORDER_VALUES)[number];
4546

4647
export type PermanentFeatureFlags = {
@@ -630,23 +631,30 @@ export const storedUserPreferencesProps: Required<{
630631
global: true,
631632
description: {
632633
short: 'Default Sort for Query Bar',
633-
long: 'All queries executed from the query bar will apply this sort.',
634+
long: 'All queries executed from the query bar will apply this sort. Not available for views and timeseries.',
635+
longReact: (
636+
<>
637+
All queries executed from the query bar will apply this sort.{' '}
638+
<strong>Not available for views and timeseries.</strong>
639+
</>
640+
),
634641
options: {
635642
'': {
636-
label: '$natural: 1 (MongoDB server default)',
637-
description: 'in natural order of documents',
638-
},
639-
'{ $natural: -1 }': {
640-
label: '$natural: -1',
641-
description: 'in reverse natural order of documents',
643+
label: 'MongoDB server default',
644+
description: 'Return documents in natural order of documents',
642645
},
643646
'{ _id: 1 }': {
644647
label: '_id: 1',
645-
description: 'in ascending order by id',
648+
description: 'Return documents in ascending order by id',
646649
},
647650
'{ _id: -1 }': {
648651
label: '_id: -1',
649-
description: 'in descending order by id',
652+
description: 'Return documents in in descending order by id',
653+
},
654+
'{ $natural: -1 }': {
655+
label: '$natural: -1',
656+
description:
657+
'Return documents in reverse natural order, but ignores existing indexes. ⚠️ Suitable if you use Compass only with development clusters. Avoid this option if you connect to production clusters as well.',
650658
},
651659
},
652660
},

0 commit comments

Comments
 (0)