Skip to content

Commit 76f3693

Browse files
perf: skip validation for default timezones (#16129)
Payload's 48 hardcoded default timezones were being validated with `new Intl.DateTimeFormat()` on every cold start. This is unnecessary since they're known to be valid. This change pre-computes a `Set` of default timezone values at module load and skips validation for any timezone in that set. Custom/user-provided timezones are still validated. ### Before/After | Operation | Before | After | |-----------|--------|-------| | `sanitizeAdminConfig` | 9.18ms | 0.17ms | | `validateTimezones` | 9.06ms | 0.03ms |
1 parent a65e715 commit 76f3693

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/payload/src/utilities/validateTimezones.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { Timezone } from '../config/types.js'
22

33
import { InvalidConfiguration } from '../errors/index.js'
4+
import { defaultTimezones } from '../fields/baseFields/timezone/defaultTimezones.js'
5+
6+
// Pre-computed Set of default timezone values - skip validation for these
7+
const defaultTimezoneValues = new Set(defaultTimezones.map((tz) => tz.value))
48

59
type ValidateTimezonesArgs = {
610
/**
@@ -91,6 +95,10 @@ export const validateTimezones = ({ source, timezones }: ValidateTimezonesArgs):
9195
}
9296

9397
for (const timezone of timezones) {
98+
// Skip validation for known-valid default timezones
99+
if (defaultTimezoneValues.has(timezone.value)) {
100+
continue
101+
}
94102
if (!isTimezoneSupported(timezone.value)) {
95103
const sourceText = source ? ` in ${source}` : ''
96104
throw new InvalidConfiguration(

0 commit comments

Comments
 (0)