Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/compass-crud/src/stores/crud-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export type CrudStoreOptions = Pick<
| 'namespace'
| 'isTimeSeries'
| 'isSearchIndexesSupported'
| 'sourceName'
> & {
noRefreshOnConfigure?: boolean;
};
Expand Down Expand Up @@ -1652,12 +1653,19 @@ class CrudStoreImpl
countOptions.hint = '_id_';
}

const isView = this.options.isReadonly && this.options.sourceName;
// Default sort options that we allow to choose from in settings will have a
// massive negative effect on the query performance for views and view-like
// collections in all cases. To avoid that, we're not applying default sort
// for those
const allowDefaultSort = !isView && !this.options.isTimeSeries;

const { defaultSortOrder } = this.preferences.getPreferences();

let sort = query.sort;
if (!sort && this.preferences.getPreferences().defaultSortOrder) {
sort = validate(
'sort',
this.preferences.getPreferences().defaultSortOrder
);

if (!sort && allowDefaultSort && defaultSortOrder) {
sort = validate('sort', defaultSortOrder);
}

const findOptions = {
Expand Down
28 changes: 18 additions & 10 deletions packages/compass-preferences-model/src/preferences-schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ const enableDbAndCollStatsDescription: React.ReactNode = (

export const SORT_ORDER_VALUES = [
'',
'{ $natural: -1 }',
'{ _id: 1 }',
'{ _id: -1 }',
'{ $natural: -1 }',
] as const;

export type SORT_ORDERS = (typeof SORT_ORDER_VALUES)[number];

export type PermanentFeatureFlags = {
Expand Down Expand Up @@ -630,23 +631,30 @@ export const storedUserPreferencesProps: Required<{
global: true,
description: {
short: 'Default Sort for Query Bar',
long: 'All queries executed from the query bar will apply this sort.',
long: 'All queries executed from the query bar will apply this sort. Not available for views and timeseries.',
longReact: (
<>
All queries executed from the query bar will apply this sort.{' '}
<strong>Not available for views and timeseries.</strong>
</>
),
options: {
'': {
label: '$natural: 1 (MongoDB server default)',
description: 'in natural order of documents',
},
'{ $natural: -1 }': {
label: '$natural: -1',
description: 'in reverse natural order of documents',
label: 'MongoDB server default',
description: 'Return documents in natural order of documents',
},
'{ _id: 1 }': {
label: '_id: 1',
description: 'in ascending order by id',
description: 'Return documents in ascending order by id',
},
'{ _id: -1 }': {
label: '_id: -1',
description: 'in descending order by id',
description: 'Return documents in in descending order by id',
},
'{ $natural: -1 }': {
label: '$natural: -1',
description:
'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.',
},
},
},
Expand Down
Loading