diff --git a/app/routes/admin.audio-upload.new.ts b/app/routes/admin.audio-upload.new.ts index f56f5c6a..0722331c 100644 --- a/app/routes/admin.audio-upload.new.ts +++ b/app/routes/admin.audio-upload.new.ts @@ -45,6 +45,16 @@ async function getFileFromFormData(request: Request): Promise { const form = await unstable_parseMultipartFormData(request, uploadHandler); + // Run garbage collection immediately to free up memory (and save money on + // resource usage). If we don't do this, the file will be kept in memory until + // V8 decides to run garbage collection, which doesn't happen very often in + // a server environment. + if (globalThis.gc) { + globalThis.gc(); + } else { + console.warn('globalThis.gc is not available. Run with --expose-gc flag.'); + } + const file = form.get(UPLOAD_AUDIO_FORM_KEY); if (typeof file === 'string' || file === null) throw badRequest(); diff --git a/start.sh b/start.sh index e95b4b3e..632c9f30 100755 --- a/start.sh +++ b/start.sh @@ -1,3 +1,6 @@ #!/bin/sh -npx prisma migrate deploy && NPM_CONFIG_UPDATE_NOTIFIER=false npm run start +set -ex + +npx prisma migrate deploy +NPM_CONFIG_UPDATE_NOTIFIER=false node --expose-gc node_modules/.bin/remix-serve build/server/index.js