@@ -10,6 +10,11 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
10
10
try {
11
11
const qManifest = QManifest . parse ( await request . json ( ) ) ;
12
12
const manifestHash = qManifest . manifestHash ;
13
+
14
+ console . log (
15
+ `Processing manifest ${ manifestHash } for API key ${ publicApiKey } with ${ Object . keys ( qManifest . symbols ) . length } symbols`
16
+ ) ;
17
+
13
18
exit ( ) ;
14
19
const db = getDB ( ) ;
15
20
await dbGetManifestInfo ( db , publicApiKey , manifestHash ) ;
@@ -24,9 +29,16 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
24
29
)
25
30
. limit ( 1000 )
26
31
. all ( ) ;
32
+
33
+ console . log ( `Found ${ existing . length } existing symbols for manifest ${ manifestHash } ` ) ;
34
+
27
35
const existingMap = new Map < string , ( typeof existing ) [ 0 ] > ( ) ;
28
36
existing . forEach ( ( row ) => existingMap . set ( row . hash , row ) ) ;
29
37
const promises : Promise < any > [ ] = [ ] ;
38
+
39
+ let insertCount = 0 ;
40
+ let updateCount = 0 ;
41
+
30
42
for ( const symbol of Object . values ( qManifest . symbols ) ) {
31
43
const existing = existingMap . get ( symbol . hash ) ;
32
44
const lo = symbol . loc [ 0 ] ;
@@ -38,6 +50,7 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
38
50
existing . lo !== lo ||
39
51
existing . hi !== hi
40
52
) {
53
+ updateCount ++ ;
41
54
promises . push (
42
55
db
43
56
. update ( symbolDetailTable )
@@ -49,9 +62,14 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
49
62
} )
50
63
. where ( eq ( symbolDetailTable . id , existing . id ) )
51
64
. run ( )
65
+ . catch ( ( error ) => {
66
+ console . error ( `Failed to update symbol ${ symbol . hash } :` , error ) ;
67
+ throw error ;
68
+ } )
52
69
) ;
53
70
}
54
71
} else {
72
+ insertCount ++ ;
55
73
promises . push (
56
74
db
57
75
. insert ( symbolDetailTable )
@@ -65,6 +83,20 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
65
83
hi,
66
84
} )
67
85
. run ( )
86
+ . catch ( ( error ) => {
87
+ console . error (
88
+ `Failed to insert symbol ${ symbol . hash } for manifest ${ manifestHash } :` ,
89
+ {
90
+ error : error . message ,
91
+ symbol : {
92
+ hash : symbol . hash ,
93
+ displayName : symbol . displayName ,
94
+ origin : symbol . origin ,
95
+ } ,
96
+ }
97
+ ) ;
98
+ throw error ;
99
+ } )
68
100
) ;
69
101
}
70
102
if ( promises . length > 10 ) {
@@ -73,9 +105,17 @@ export const onPost: RequestHandler = async ({ exit, json, request, params }) =>
73
105
}
74
106
}
75
107
await Promise . all ( promises ) ;
108
+
109
+ console . log (
110
+ `Successfully processed manifest ${ manifestHash } : ${ insertCount } inserts, ${ updateCount } updates`
111
+ ) ;
76
112
json ( 200 , { code : 200 , message : 'OK' } ) ;
77
113
} catch ( e ) {
78
- console . error ( JSON . stringify ( e ) ) ;
114
+ console . error ( `Error processing manifest for API key ${ publicApiKey } :` , {
115
+ error : e instanceof Error ? e . message : String ( e ) ,
116
+ stack : e instanceof Error ? e . stack : undefined ,
117
+ publicApiKey,
118
+ } ) ;
79
119
json ( 500 , { code : 500 , message : 'Internal Server Error' , error : e } ) ;
80
120
}
81
121
} ;
0 commit comments