File tree Expand file tree Collapse file tree 2 files changed +56
-15
lines changed Expand file tree Collapse file tree 2 files changed +56
-15
lines changed Original file line number Diff line number Diff line change
1
+ import { type DataFunctionArgs } from "@remix-run/node" ;
2
+ import { PerformanceObserver } from "node:perf_hooks" ;
3
+ import { runInNewContext } from "node:vm" ;
4
+ import v8 from "v8" ;
5
+ import { requireUser } from "~/services/session.server" ;
6
+
7
+ async function waitTillGcFinishes ( ) {
8
+ let resolver : ( value : PerformanceEntry ) => void ;
9
+ let rejector : ( reason ?: any ) => void ;
10
+
11
+ const promise = new Promise < PerformanceEntry > ( ( resolve , reject ) => {
12
+ resolver = resolve ;
13
+ rejector = reject ;
14
+ } ) ;
15
+
16
+ const obs = new PerformanceObserver ( ( list ) => {
17
+ const entry = list . getEntries ( ) [ 0 ] ;
18
+
19
+ if ( entry . name === "gc" ) {
20
+ resolver ( entry ) ;
21
+ }
22
+ } ) ;
23
+
24
+ obs . observe ( { entryTypes : [ "gc" ] } ) ;
25
+
26
+ v8 . setFlagsFromString ( "--expose-gc" ) ;
27
+ const gc = global . gc ?? runInNewContext ( "gc" ) ;
28
+
29
+ gc ( ) ;
30
+
31
+ // disable expose-gc
32
+ v8 . setFlagsFromString ( "--noexpose-gc" ) ;
33
+
34
+ return promise ;
35
+ }
36
+
37
+ export async function loader ( { request } : DataFunctionArgs ) {
38
+ const user = await requireUser ( request ) ;
39
+
40
+ if ( ! user . admin ) {
41
+ throw new Response ( "You must be an admin to perform this action" , { status : 403 } ) ;
42
+ }
43
+
44
+ const entry = await waitTillGcFinishes ( ) ;
45
+
46
+ return new Response ( JSON . stringify ( entry ) , {
47
+ status : 200 ,
48
+ headers : {
49
+ "Content-Type" : "application/json" ,
50
+ } ,
51
+ } ) ;
52
+ }
Original file line number Diff line number Diff line change 1
- import path from "path" ;
2
- import os from "os" ;
1
+ import { type DataFunctionArgs } from "@remix-run/node" ;
3
2
import fs from "fs" ;
4
- import v8 from "v8" ;
3
+ import os from "os" ;
4
+ import path from "path" ;
5
5
import { PassThrough } from "stream" ;
6
- import { json , type DataFunctionArgs } from "@remix-run/node" ;
7
- import { prisma } from "~/db.server" ;
8
- import { authenticateApiRequest } from "~/services/apiAuth.server" ;
6
+ import v8 from "v8" ;
9
7
import { requireUser } from "~/services/session.server" ;
10
- import { runInNewContext } from "node:vm" ;
11
8
12
9
// Format date as yyyy-MM-dd HH_mm_ss_SSS
13
10
function formatDate ( date : Date ) {
@@ -33,14 +30,6 @@ export async function loader({ request }: DataFunctionArgs) {
33
30
throw new Response ( "You must be an admin to perform this action" , { status : 403 } ) ;
34
31
}
35
32
36
- v8 . setFlagsFromString ( "--expose-gc" ) ;
37
- const gc = global . gc ?? runInNewContext ( "gc" ) ;
38
-
39
- gc ( ) ;
40
-
41
- // disable expose-gc
42
- v8 . setFlagsFromString ( "--noexpose-gc" ) ;
43
-
44
33
const tempDir = os . tmpdir ( ) ;
45
34
const filepath = path . join (
46
35
tempDir ,
You can’t perform that action at this time.
0 commit comments