Skip to content

Commit 0c7234c

Browse files
committed
fix(updates): use cache for checking for updates
1 parent e9a8b35 commit 0c7234c

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

packages/workshop-app/app/root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
getUserInfo,
1313
userHasAccessToWorkshop,
1414
} from '@epic-web/workshop-utils/epic-api.server'
15-
import { checkForUpdates } from '@epic-web/workshop-utils/git.server'
15+
import { checkForUpdatesCached } from '@epic-web/workshop-utils/git.server'
1616
import { makeTimings } from '@epic-web/workshop-utils/timing.server'
1717
import {
1818
getSetClientIdCookieHeader,
@@ -122,7 +122,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
122122
user: getUserInfo(),
123123
userHasAccess: userHasAccessToWorkshop({ request, timings }),
124124
apps: getApps({ request, timings }),
125-
repoUpdates: checkForUpdates(),
125+
repoUpdates: checkForUpdatesCached(),
126126
unmutedNotifications: getUnmutedNotifications(),
127127
})
128128

packages/workshop-app/app/routes/admin+/update-repo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { spawn } from 'child_process'
22
import {
3-
checkForUpdates,
3+
checkForUpdatesCached,
44
updateLocalRepo,
55
} from '@epic-web/workshop-utils/git.server'
66
import { json } from '@remix-run/node'
@@ -9,7 +9,7 @@ import { useEffect, useRef } from 'react'
99
import { toast } from 'sonner'
1010

1111
export async function action() {
12-
const updates = await checkForUpdates()
12+
const updates = await checkForUpdatesCached()
1313
if (!updates.updatesAvailable) {
1414
return json({ type: 'error', error: 'No updates available' } as const, {
1515
status: 400,

packages/workshop-app/server/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
init as initApps,
99
setModifiedTimesForAppDirs,
1010
} from '@epic-web/workshop-utils/apps.server'
11-
import { checkForUpdates } from '@epic-web/workshop-utils/git.server'
11+
import { checkForUpdatesCached } from '@epic-web/workshop-utils/git.server'
1212
import { checkConnectionCached } from '@epic-web/workshop-utils/utils.server'
1313
import { createRequestHandler } from '@remix-run/express'
1414
import { type ServerBuild } from '@remix-run/node'
@@ -50,7 +50,7 @@ const epicshopAppRootDir = isRunningInBuildDir
5050
: path.join(__dirname, '..')
5151

5252
// kick this off early...
53-
const hasUpdatesPromise = checkForUpdates()
53+
const hasUpdatesPromise = checkForUpdatesCached()
5454
// warm up some caches
5555
void getApps()
5656
void checkConnectionCached()

packages/workshop-utils/src/git.server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { execa, execaCommand } from 'execa'
22
import { getWorkshopRoot } from './apps.server.js'
3+
import { cachified, checkForUpdatesCache } from './cache.server.js'
34
import { getWorkshopConfig } from './config.server.js'
45
import { getErrorMessage } from './utils.js'
56
import { checkConnection } from './utils.server.js'
@@ -87,6 +88,17 @@ export async function checkForUpdates() {
8788
}
8889
}
8990

91+
export async function checkForUpdatesCached() {
92+
const key = 'checkForUpdates'
93+
return cachified({
94+
ttl: 1000 * 60,
95+
swr: 1000 * 60 * 60 * 24,
96+
key,
97+
getFreshValue: checkForUpdates,
98+
cache: checkForUpdatesCache,
99+
})
100+
}
101+
90102
export async function updateLocalRepo() {
91103
const cwd = getWorkshopRoot()
92104
try {

0 commit comments

Comments
 (0)