Skip to content

Commit 29f02c3

Browse files
committed
change to use limit as pref
1 parent 527b99f commit 29f02c3

File tree

8 files changed

+52
-82
lines changed

8 files changed

+52
-82
lines changed

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-options/pipeline-collation.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import type { RootState } from '../../../modules';
1515
import { collationStringChanged } from '../../../modules/collation-string';
1616
import { maxTimeMSChanged } from '../../../modules/max-time-ms';
17-
import { DEFAULT_MAX_TIME_MS, WEB_MAX_TIME_MS_LIMIT } from '../../../constants';
17+
import { DEFAULT_MAX_TIME_MS } from '../../../constants';
1818
import { usePreference } from 'compass-preferences-model/provider';
1919

2020
const pipelineOptionsContainerStyles = css({
@@ -59,46 +59,46 @@ const PipelineCollation: React.FunctionComponent<PipelineCollationProps> = ({
5959
maxTimeMSValue,
6060
maxTimeMSChanged,
6161
}) => {
62-
const showMaxTimeMSWarning = Boolean(usePreference('showMaxTimeMSWarning'));
62+
const maxTimeMSEnvLimit = usePreference('maxTimeMSEnvLimit');
6363

6464
const onMaxTimeMSChanged = useCallback(
6565
(evt: React.ChangeEvent<HTMLInputElement>) => {
6666
if (maxTimeMSChanged) {
6767
const parsed = Number(evt.currentTarget.value);
6868
const newValue = Number.isNaN(parsed) ? 0 : parsed;
6969

70-
// When warning is enabled, enforce the hard limit
71-
if (showMaxTimeMSWarning && newValue > WEB_MAX_TIME_MS_LIMIT) {
72-
maxTimeMSChanged(WEB_MAX_TIME_MS_LIMIT);
70+
// When environment limit is set (> 0), enforce it
71+
if (maxTimeMSEnvLimit && newValue > maxTimeMSEnvLimit) {
72+
maxTimeMSChanged(maxTimeMSEnvLimit);
7373
} else {
7474
maxTimeMSChanged(newValue);
7575
}
7676
}
7777
},
78-
[maxTimeMSChanged, showMaxTimeMSWarning]
78+
[maxTimeMSChanged, maxTimeMSEnvLimit]
7979
);
8080

8181
const maxTimeMSLimit = usePreference('maxTimeMS');
8282

83-
// Determine the effective max limit when warning is enabled
83+
// Determine the effective max limit when environment limit is set (> 0)
8484
const effectiveMaxLimit = useMemo(() => {
85-
if (showMaxTimeMSWarning) {
85+
if (maxTimeMSEnvLimit) {
8686
return maxTimeMSLimit
87-
? Math.min(maxTimeMSLimit, WEB_MAX_TIME_MS_LIMIT)
88-
: WEB_MAX_TIME_MS_LIMIT;
87+
? Math.min(maxTimeMSLimit, maxTimeMSEnvLimit)
88+
: maxTimeMSEnvLimit;
8989
}
9090
return maxTimeMSLimit;
91-
}, [showMaxTimeMSWarning, maxTimeMSLimit]);
91+
}, [maxTimeMSEnvLimit, maxTimeMSLimit]);
9292

93-
// Check if value exceeds the limit when warning is enabled
93+
// Check if value exceeds the environment limit (when limit > 0)
9494
const exceedsLimit = Boolean(
9595
useMemo(() => {
9696
return (
97-
showMaxTimeMSWarning &&
97+
maxTimeMSEnvLimit &&
9898
maxTimeMSValue &&
99-
maxTimeMSValue >= WEB_MAX_TIME_MS_LIMIT
99+
maxTimeMSValue >= maxTimeMSEnvLimit
100100
);
101-
}, [showMaxTimeMSWarning, maxTimeMSValue])
101+
}, [maxTimeMSEnvLimit, maxTimeMSValue])
102102
);
103103

104104
return (

packages/compass-aggregations/src/constants.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/**
2-
* Data Explorer limits (5 minutes = 300,000ms)
3-
* This limit is artificial but necessary for the backend that powers DE.
4-
* https://github.com/10gen/mms/blob/dea184f4a40db0a64ed0d6665d36265f62ae4f65/server/src/main/com/xgen/cloud/services/clusterconnection/runtime/ws/ClusterConnectionServerProvider.java#L50-L51
5-
*/
6-
export const WEB_MAX_TIME_MS_LIMIT = 300_000;
7-
81
/**
92
* Default for maxTimeMS option.
103
*/

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export type UserConfigurablePreferences = PermanentFeatureFlags &
106106
proxy: string;
107107
inferNamespacesFromPrivileges?: boolean;
108108
// Features that are enabled by default in Date Explorer, but are disabled in Compass
109-
showMaxTimeMSWarning?: boolean;
109+
maxTimeMSEnvLimit?: number;
110110
};
111111

112112
/**
@@ -1064,15 +1064,16 @@ export const storedUserPreferencesProps: Required<{
10641064
validator: z.boolean().default(true),
10651065
type: 'boolean',
10661066
},
1067-
showMaxTimeMSWarning: {
1067+
maxTimeMSEnvLimit: {
10681068
ui: true,
10691069
cli: true,
10701070
global: true,
10711071
description: {
1072-
short: 'Show Max Time MS over 5min Warning for Data Explorer',
1072+
short:
1073+
'Maximum time limit for operations in environment (milliseconds). Set to 0 for no limit.',
10731074
},
1074-
validator: z.boolean().default(false),
1075-
type: 'boolean',
1075+
validator: z.number().min(0).default(0),
1076+
type: 'number',
10761077
},
10771078

10781079
...allFeatureFlagsProps,

packages/compass-query-bar/src/components/query-option.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import {
1111
} from '@mongodb-js/compass-components';
1212
import { connect } from '../stores/context';
1313
import OptionEditor from './option-editor';
14-
import {
15-
OPTION_DEFINITION,
16-
WEB_MAX_TIME_MS_LIMIT,
17-
} from '../constants/query-option-definition';
14+
import { OPTION_DEFINITION } from '../constants/query-option-definition';
1815
import type {
1916
QueryOptionOfTypeDocument,
2017
QueryOption as QueryOptionType,
@@ -159,7 +156,7 @@ const QueryOption: React.FunctionComponent<QueryOptionProps> = ({
159156
}, [track, name, connectionInfoRef]);
160157

161158
// MaxTimeMS warning tooltip logic
162-
const showMaxTimeMSWarning = Boolean(usePreference('showMaxTimeMSWarning'));
159+
const maxTimeMSEnvLimit = usePreference('maxTimeMSEnvLimit');
163160
const numericValue = useMemo(() => {
164161
if (!value) return 0;
165162
const parsed = Number(value);
@@ -169,10 +166,10 @@ const QueryOption: React.FunctionComponent<QueryOptionProps> = ({
169166
const exceedsMaxTimeMSLimit = useMemo(() => {
170167
return (
171168
name === 'maxTimeMS' &&
172-
showMaxTimeMSWarning &&
173-
numericValue >= WEB_MAX_TIME_MS_LIMIT
169+
maxTimeMSEnvLimit && // 0 is falsy, so no limit when 0
170+
numericValue >= maxTimeMSEnvLimit
174171
);
175-
}, [name, showMaxTimeMSWarning, numericValue]);
172+
}, [name, maxTimeMSEnvLimit, numericValue]);
176173

177174
return (
178175
<div

packages/compass-query-bar/src/constants/query-option-definition.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ export type QueryOptionOfTypeDocument = Exclude<
99
'maxTimeMS' | 'limit' | 'skip'
1010
>;
1111

12-
/**
13-
* Data Explorer limits (5 minutes = 300,000ms)
14-
* This limit is artificial but necessary for the backend that powers DE.
15-
* https://github.com/10gen/mms/blob/dea184f4a40db0a64ed0d6665d36265f62ae4f65/server/src/main/com/xgen/cloud/services/clusterconnection/runtime/ws/ClusterConnectionServerProvider.java#L50-L51
16-
*/
17-
export const WEB_MAX_TIME_MS_LIMIT = 300_000;
18-
1912
export const OPTION_DEFINITION: {
2013
[optionName in QueryOption]: {
2114
name: optionName;
@@ -77,14 +70,13 @@ export const OPTION_DEFINITION: {
7770
link: 'https://docs.mongodb.com/manual/reference/method/cursor.maxTimeMS/',
7871
extraTextInputProps() {
7972
const preferenceMaxTimeMS = usePreference('maxTimeMS');
80-
const showMaxTimeMSWarning =
81-
usePreference('showMaxTimeMSWarning') ?? false;
73+
const maxTimeMSEnvLimit = usePreference('maxTimeMSEnvLimit');
8274

83-
// Determine the effective max limit when warning is enabled
84-
const effectiveMaxLimit = showMaxTimeMSWarning
75+
// Determine the effective max limit when environment limit is set (> 0)
76+
const effectiveMaxLimit = maxTimeMSEnvLimit
8577
? preferenceMaxTimeMS
86-
? Math.min(preferenceMaxTimeMS, WEB_MAX_TIME_MS_LIMIT)
87-
: WEB_MAX_TIME_MS_LIMIT
78+
? Math.min(preferenceMaxTimeMS, maxTimeMSEnvLimit)
79+
: maxTimeMSEnvLimit
8880
: preferenceMaxTimeMS;
8981

9082
const props: {
@@ -94,8 +86,8 @@ export const OPTION_DEFINITION: {
9486
max: effectiveMaxLimit,
9587
};
9688

97-
if (effectiveMaxLimit !== undefined && effectiveMaxLimit < 60000) {
98-
props.placeholder = String(effectiveMaxLimit);
89+
if (effectiveMaxLimit && effectiveMaxLimit < 60000) {
90+
props.placeholder = `${+effectiveMaxLimit}`;
9991
}
10092

10193
return props;

packages/compass-query-bar/src/stores/query-bar-reducer.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type QueryBarState = {
5252

5353
export const INITIAL_STATE: QueryBarState = {
5454
isReadonlyConnection: false,
55-
fields: mapQueryToFormFields({}, DEFAULT_FIELD_VALUES),
55+
fields: mapQueryToFormFields({ maxTimeMSEnvLimit: 0 }, DEFAULT_FIELD_VALUES),
5656
expanded: false,
5757
serverVersion: '3.6.0',
5858
lastAppliedQuery: { source: null, query: {} },
@@ -103,9 +103,7 @@ export const changeField = (
103103
return (dispatch, getState, { preferences }) => {
104104
const parsedValue = validateField(name, stringValue, {
105105
maxTimeMS: preferences.getPreferences().maxTimeMS ?? undefined,
106-
showMaxTimeMSWarning: Boolean(
107-
preferences.getPreferences().showMaxTimeMSWarning
108-
),
106+
maxTimeMSEnvLimit: preferences.getPreferences().maxTimeMSEnvLimit,
109107
});
110108
const isValid = parsedValue !== false;
111109
dispatch({
@@ -165,11 +163,7 @@ export const resetQuery = (
165163
return false;
166164
}
167165
const fields = mapQueryToFormFields(
168-
{
169-
maxTimeMS: preferences.getPreferences().maxTimeMS,
170-
showMaxTimeMSWarning:
171-
preferences.getPreferences().showMaxTimeMSWarning ?? false,
172-
},
166+
preferences.getPreferences(),
173167
DEFAULT_FIELD_VALUES
174168
);
175169
dispatch({ type: QueryBarActions.ResetQuery, fields, source });
@@ -186,10 +180,7 @@ export const setQuery = (
186180
query: BaseQuery
187181
): QueryBarThunkAction<void, SetQueryAction> => {
188182
return (dispatch, getState, { preferences }) => {
189-
const fields = mapQueryToFormFields(
190-
{ maxTimeMS: preferences.getPreferences().maxTimeMS },
191-
query
192-
);
183+
const fields = mapQueryToFormFields(preferences.getPreferences(), query);
193184
dispatch({ type: QueryBarActions.SetQuery, fields });
194185
};
195186
};
@@ -245,14 +236,11 @@ export const applyFromHistory = (
245236
}
246237
return acc;
247238
}, {});
248-
const fields = mapQueryToFormFields(
249-
{ maxTimeMS: preferences.getPreferences().maxTimeMS },
250-
{
251-
...DEFAULT_FIELD_VALUES,
252-
...query,
253-
...currentQuery,
254-
}
255-
);
239+
const fields = mapQueryToFormFields(preferences.getPreferences(), {
240+
...DEFAULT_FIELD_VALUES,
241+
...query,
242+
...currentQuery,
243+
});
256244
dispatch({
257245
type: QueryBarActions.ApplyFromHistory,
258246
fields,

packages/compass-query-bar/src/utils/query.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {
1414
QueryProperty,
1515
} from '../constants/query-properties';
1616
import { QUERY_PROPERTIES } from '../constants/query-properties';
17-
import { WEB_MAX_TIME_MS_LIMIT } from '../constants/query-option-definition';
1817

1918
export function mapFormFieldsToQuery(fields: QueryFormFields): BaseQuery {
2019
// We always want filter field to be in the query, even if the field
@@ -57,7 +56,7 @@ export function doesQueryHaveExtraOptionsSet(fields?: QueryFormFields) {
5756

5857
export function parseQueryAttributesToFormFields(
5958
query: Record<string, unknown>,
60-
preferences: Pick<UserPreferences, 'maxTimeMS' | 'showMaxTimeMSWarning'>
59+
preferences: Pick<UserPreferences, 'maxTimeMS' | 'maxTimeMSEnvLimit'>
6160
): QueryFormFields {
6261
return Object.fromEntries(
6362
Object.entries(query)
@@ -82,7 +81,7 @@ export function parseQueryAttributesToFormFields(
8281
* Map query document to the query fields state only preserving valid values
8382
*/
8483
export function mapQueryToFormFields(
85-
preferences: Pick<UserPreferences, 'maxTimeMS' | 'showMaxTimeMSWarning'>,
84+
preferences: Pick<UserPreferences, 'maxTimeMS' | 'maxTimeMSEnvLimit'>,
8685
query?: BaseQuery,
8786
onlyValid = true
8887
): QueryFormFields {
@@ -128,8 +127,8 @@ export function validateField(
128127
value: string,
129128
{
130129
maxTimeMS: preferencesMaxTimeMS,
131-
showMaxTimeMSWarning,
132-
}: Pick<UserPreferences, 'maxTimeMS' | 'showMaxTimeMSWarning'>
130+
maxTimeMSEnvLimit,
131+
}: Pick<UserPreferences, 'maxTimeMS' | 'maxTimeMSEnvLimit'>
133132
) {
134133
const validated = validate(field, value);
135134
if (field === 'filter' && validated === '') {
@@ -141,15 +140,15 @@ export function validateField(
141140
}
142141

143142
// Additional validation for maxTimeMS to make sure that we are not over the
144-
// upper bound set in preferences or Data Explorer limits
143+
// upper bound set in preferences or environment limits
145144
if (field === 'maxTimeMS') {
146145
const maxTimeMS = Number(value);
147146

148-
// When warning is enabled, enforce hard limit
147+
// When environment limit is set (> 0), enforce it
149148
if (
150-
showMaxTimeMSWarning &&
149+
maxTimeMSEnvLimit &&
151150
!Number.isNaN(maxTimeMS) &&
152-
maxTimeMS > WEB_MAX_TIME_MS_LIMIT
151+
maxTimeMS > maxTimeMSEnvLimit
153152
) {
154153
return false;
155154
}
@@ -175,7 +174,7 @@ export function validateField(
175174

176175
export function isQueryFieldsValid(
177176
fields: QueryFormFields,
178-
preferences: Pick<UserPreferences, 'maxTimeMS' | 'showMaxTimeMSWarning'>
177+
preferences: Pick<UserPreferences, 'maxTimeMS' | 'maxTimeMSEnvLimit'>
179178
) {
180179
return Object.entries(fields).every(
181180
([key, value]) => validateField(key, value.string, preferences) !== false

packages/compass-web/src/entrypoint.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ const CompassWeb = ({
384384
});
385385
const preferencesAccess = useCompassWebPreferences({
386386
...initialPreferences,
387-
showMaxTimeMSWarning: true,
387+
maxTimeMSEnvLimit: 300_000, // 5 minutes limit for Data Explorer
388388
});
389389
// TODO (COMPASS-9565): My Queries feature flag will be used to conditionally provide storage providers
390390
const initialWorkspaceRef = useRef(initialWorkspace);

0 commit comments

Comments
 (0)