Skip to content

Commit

Permalink
Don't nullify cache (tldraw#5310)
Browse files Browse the repository at this point in the history
accidentally introduced a couple of minor bugs by nullifying the cache,
so in this PR i make it so that the interval just starts and stops
rather than completely getting rid of the cache.

### Change type

- [x] `bugfix`
  • Loading branch information
ds300 authored Jan 29, 2025
1 parent b53fbf4 commit ff19d0d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/dotcom/client/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const LoginRedirectPage = lazy(() => import('./components/LoginRedirectPage/Logi
export const tlaOverrideFlag = 'tla-override-flag'
export const tlaProbablyLoggedInFlag = 'tla-probably-logged-in-flag'

const isOverrideFlagSet = !!getFromLocalStorage(tlaOverrideFlag) || navigator.webdriver
export const isOverrideFlagSet = !!getFromLocalStorage(tlaOverrideFlag) || navigator.webdriver
const isProbablyLoggedIn = !!getFromLocalStorage(tlaProbablyLoggedInFlag)

export function SetPreviewFlag(props: PropsWithChildren) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useEditor,
useValue,
} from 'tldraw'
import { isOverrideFlagSet } from '../../../routes'
import { getScratchPersistenceKey } from '../../../utils/scratch-persistence-key'
import { useApp } from '../../hooks/useAppState'
import { useCurrentFileId } from '../../hooks/useCurrentFileId'
Expand Down Expand Up @@ -126,7 +127,7 @@ export function PreviewWelcomeDialog() {
)

useEffect(() => {
if (shouldShowWelcomeDialog) {
if (shouldShowWelcomeDialog && !isOverrideFlagSet) {
userHasSlurpableDocument().then((hasSlurpableDocument) => {
dialogs.addDialog({
id: dialogId,
Expand Down
5 changes: 2 additions & 3 deletions apps/dotcom/sync-worker/src/TLUserDurableObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class TLUserDurableObject extends DurableObject<Environment> {

private assertCache(): asserts this is { cache: UserDataSyncer } {
assert(this.cache, 'no cache')
this.cache.maybeStartInterval()
}

private readonly sockets = new Set<WebSocket>()
Expand All @@ -146,9 +147,7 @@ export class TLUserDurableObject extends DurableObject<Environment> {

maybeClose() {
if (this.sockets.size === 0) {
this.cache?.close()
this.cache = null
// db will time out after 10 seconds of inactivity so no need to close it manually
this.cache?.stopInterval()
}
}

Expand Down
15 changes: 11 additions & 4 deletions apps/dotcom/sync-worker/src/UserDataSyncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class UserDataSyncer {
}
}

interval
interval: NodeJS.Timeout | null = null

constructor(
private ctx: DurableObjectState,
Expand All @@ -131,12 +131,19 @@ export class UserDataSyncer {
this.sentry = createSentry(ctx, env)
this.replicator = getReplicator(env)
this.reboot(false)
}

this.interval = setInterval(() => this.__rebootIfMutationsNotCommitted(), 1000)
maybeStartInterval() {
if (!this.interval) {
this.interval = setInterval(() => this.__rebootIfMutationsNotCommitted(), 1000)
}
}

close() {
clearInterval(this.interval)
stopInterval() {
if (this.interval) {
clearInterval(this.interval)
this.interval = null
}
}

private queue = new ExecutionQueue()
Expand Down

0 comments on commit ff19d0d

Please sign in to comment.