File tree Expand file tree Collapse file tree 2 files changed +30
-25
lines changed
components/webui/server/src/routes/api/presto-search Expand file tree Collapse file tree 2 files changed +30
-25
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
43
43
tags : [ "Presto Search" ] ,
44
44
} ,
45
45
} ,
46
-
46
+ // eslint-disable-next-line max-lines-per-function
47
47
async ( request , reply ) => {
48
48
const { queryString} = request . body ;
49
49
@@ -61,13 +61,29 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
61
61
`Received ${ data . length } rows from Presto query`
62
62
) ;
63
63
64
+ if ( false === isResolved ) {
65
+ request . log . error (
66
+ "Presto data received before searchJobId was resolved; " +
67
+ "skipping insert."
68
+ ) ;
69
+
70
+ return ;
71
+ }
72
+
73
+ if ( 0 === data . length ) {
74
+ return ;
75
+ }
76
+
64
77
insertPrestoRowsToMongo ( {
65
- columns : columns ,
66
- data : data ,
67
- isResolved : isResolved ,
68
- log : request . log ,
69
- mongoDb : mongoDb ,
70
- searchJobId : searchJobId ,
78
+ columns,
79
+ data,
80
+ mongoDb,
81
+ searchJobId,
82
+ } ) . catch ( ( err : unknown ) => {
83
+ request . log . error (
84
+ err ,
85
+ "Failed to insert Presto results into MongoDB"
86
+ ) ;
71
87
} ) ;
72
88
} ,
73
89
error : ( error ) => {
Original file line number Diff line number Diff line change
1
+ import type { InsertManyResult } from "mongodb" ;
2
+
1
3
import type { InsertPrestoRowsToMongoProps } from "./typings.js" ;
2
4
3
5
@@ -28,31 +30,18 @@ const prestoRowToObject = (
28
30
* @param props.data
29
31
* @param props.columns
30
32
* @param props.searchJobId
31
- * @param props.isResolved
32
33
* @param props.mongoDb
33
- * @param props.log
34
+ * @return Promise that resolves when the insertion is complete
34
35
*/
35
36
const insertPrestoRowsToMongo = ( {
36
37
columns,
37
38
data,
38
- isResolved,
39
- log,
40
39
mongoDb,
41
40
searchJobId,
42
- } : InsertPrestoRowsToMongoProps ) : void => {
43
- if ( false === isResolved ) {
44
- log . error ( "Presto data received before searchJobId was resolved; skipping insert." ) ;
45
-
46
- return ;
47
- }
48
-
49
- if ( 0 < data . length && searchJobId ) {
50
- const collection = mongoDb . collection ( searchJobId ) ;
51
- const resultDocs = data . map ( ( row ) => prestoRowToObject ( row , columns ) ) ;
52
- collection . insertMany ( resultDocs ) . catch ( ( err : unknown ) => {
53
- log . error ( err , "Failed to insert Presto results into MongoDB" ) ;
54
- } ) ;
55
- }
41
+ } : InsertPrestoRowsToMongoProps ) : Promise < InsertManyResult < Document > > => {
42
+ const collection = mongoDb . collection ( searchJobId ) ;
43
+ const resultDocs = data . map ( ( row ) => prestoRowToObject ( row , columns ) ) ;
44
+ return collection . insertMany ( resultDocs ) ;
56
45
} ;
57
46
58
47
export { insertPrestoRowsToMongo } ;
You can’t perform that action at this time.
0 commit comments