Skip to content

Commit

Permalink
Run GC after uploading files (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwade authored Jul 10, 2024
1 parent a5ee0d4 commit 6ce7bcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/routes/admin.audio-upload.new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ async function getFileFromFormData(request: Request): Promise<globalThis.File> {

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();

Expand Down
5 changes: 4 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6ce7bcc

Please sign in to comment.