Files
supabase/apps/studio/lib/project-transition-state.ts
T
Ali Waseem 289accd7d4 chore: Update time from 10 to 20 minutes for pause projects fallback (#46479)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Minor update for long running state thresholds when updating project
sizes

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Increased the minimum threshold for recognizing long-running
operations from 10 to 20 minutes, reducing premature fallback behavior
and improving stability for longer tasks.

* **Tests**
* Updated test suite to validate the new 20-minute threshold across
default, missing, small, and larger restore scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-09 08:25:29 -06:00

56 lines
1.5 KiB
TypeScript

import { safeLocalStorage } from 'common'
export const FALLBACK_LONG_RUNNING_STATE_THRESHOLD_MINUTES = 20
// Persist long enough for same-browser reloads, but not so long that a later transition reuses stale state.
export const MAX_PERSISTED_TRANSITION_AGE_HOURS = 24
const MS_PER_MINUTE = 60 * 1000
const MS_PER_HOUR = 60 * MS_PER_MINUTE
export const minutesToMilliseconds = (minutes: number) => minutes * MS_PER_MINUTE
export const hoursToMilliseconds = (hours: number) => hours * MS_PER_HOUR
export const getPersistedTransitionStartTime = (
storageKey: string,
now = Date.now(),
maxAgeMs = Number.POSITIVE_INFINITY
) => {
if (typeof window === 'undefined') return now
const existingValue = safeLocalStorage.getItem(storageKey)
if (existingValue !== null) {
const parsedStartTime = Number(existingValue)
const elapsedMs = now - parsedStartTime
if (
Number.isFinite(parsedStartTime) &&
parsedStartTime > 0 &&
elapsedMs >= 0 &&
elapsedMs <= maxAgeMs
) {
return parsedStartTime
}
}
safeLocalStorage.setItem(storageKey, String(now))
return now
}
export const clearPersistedTransitionStartTime = (storageKey: string) => {
safeLocalStorage.removeItem(storageKey)
}
export const getRemainingTransitionTimeMs = ({
startTimeMs,
thresholdMs,
now = Date.now(),
}: {
startTimeMs: number
thresholdMs: number
now?: number
}) => {
const elapsedMs = now - startTimeMs
return Math.max(thresholdMs - elapsedMs, 0)
}