@@ -22,12 +22,7 @@ import {
2222namespace Helpers {
2323 async function insertNode ( db : IDB , node : DBNode ) {
2424 const query = new DBNode ( node ) . getDBInsertQuery ( ) ;
25- try {
26- await db . run ( query ) ;
27- } catch ( e ) {
28- console . log ( e ) ;
29- console . error ( "Failed to insert node" ) ;
30- }
25+ await db . run ( query , node ) ;
3126 }
3227
3328 export async function insertNodes ( db : IDB , nodes : DBNode [ ] ) {
@@ -41,35 +36,15 @@ export class IngestEndpoint extends ApiEndpoint {
4136 makeBodies (
4237 content : any
4338 ) : [ IngestEndpointRequestBody , IngestEndpointResponseBody ] {
44- const requestBody = JSON . parse ( content ) as IngestEndpointRequestBody ;
39+ const requestBody = content as IngestEndpointRequestBody ;
4540 const responseBody : IngestEndpointResponseBody = {
46- batchID : requestBody . batchID ,
41+ batchID : "hey" ,
4742 status : 200 ,
4843 } ;
4944
5045 return [ requestBody , responseBody ] ;
5146 }
5247
53- async commitProgress (
54- db : IDB
55- ) : Promise < IngestEndpointResponseBody [ "status" ] > {
56- try {
57- try {
58- await db . commitTransaction ( ) ;
59- } catch ( e ) {
60- console . error ( e ) ;
61- await db . rollbackTransaction ( ) ;
62-
63- return 500 ;
64- }
65- } catch ( e ) {
66- console . error ( e ) ;
67- return 500 ;
68- }
69-
70- return 200 ;
71- }
72-
7348 public async post (
7449 request : IApiRequest ,
7550 endpoint : IApiEndpointInfo ,
@@ -85,15 +60,13 @@ export class IngestEndpoint extends ApiEndpoint {
8560 nodes = nodes . map ( ( node ) => new DBNode ( node ) ) ;
8661 await Promise . all ( nodes . map ( ( x ) => x . fillEmbeddings ( embeddingModel ) ) ) ;
8762 // -----------------------------------------------------------------------------------
88-
8963 const db = new Neo4j ( http ) ;
9064 await db . verifyConnectivity ( ) ;
9165 // -----------------------------------------------------------------------------------
92- await db . beginTransaction ( ) ;
93- // -----------------------------------------------------------------------------------
94- await Helpers . insertNodes ( db , nodes ) ;
95- // -----------------------------------------------------------------------------------
96- responseBody . status = await this . commitProgress ( db ) ;
66+ const jobs = nodes . map ( ( node ) =>
67+ db . run ( new DBNode ( node ) . getDBInsertQuery ( ) , node )
68+ ) ;
69+ await Promise . all ( jobs ) ;
9770 // -----------------------------------------------------------------------------------
9871
9972 return this . success ( JSON . stringify ( responseBody ) ) ;
0 commit comments