@@ -33,7 +33,7 @@ export class EventCacheHelper {
3333 }
3434
3535 const files = await Promise . all (
36- this . filePaths ( from ) . map ( ( path ) => {
36+ this . buildFilePaths ( from ) . map ( ( path ) => {
3737 return S3Helper . listAll ( this . bucketName , path ) ;
3838 } )
3939 ) ;
@@ -91,12 +91,9 @@ export class EventCacheHelper {
9191 . split ( '\n' )
9292 . filter ( ( line ) => line . trim ( ) )
9393 . map ( ( line ) => {
94- const snsWrapper = JSON . parse ( line ) ;
95-
96- const message = JSON . parse ( snsWrapper . Message ) ;
97-
98- const { data, success, error } =
99- $NHSNotifyTemplateEvent . safeParse ( message ) ;
94+ const { data, success, error } = $NHSNotifyTemplateEvent . safeParse (
95+ JSON . parse ( line )
96+ ) ;
10097
10198 if ( ! success ) {
10299 throw new Error (
@@ -118,34 +115,32 @@ export class EventCacheHelper {
118115
119116 /*
120117 * Get files paths for the current hour
121- * and next hour if the different in seconds is greater than toleranceInSeconds
118+ * and next hour if the difference in seconds is greater than toleranceInSeconds
122119 *
123120 * The way firehose stores files is yyyy/mm/dd/hh.
124121 * On a boundary of 15:59:58 you'll find files in both 15 and 16 hour folders
125122 */
126- private filePaths ( start : Date , toleranceInSeconds = 30 ) : string [ ] {
127- const paths = [ this . getEventCachePrefix ( start ) ] ;
123+ private buildFilePaths ( start : Date , toleranceInSeconds = 30 ) : string [ ] {
124+ const paths = [ this . buildPathPrefix ( start ) ] ;
128125
129126 const end = addHours ( start , 1 ) ;
130127
131128 const difference = differenceInSeconds ( end , start ) ;
132129
133130 if ( difference >= toleranceInSeconds ) {
134- paths . push ( this . getEventCachePrefix ( end ) ) ;
131+ paths . push ( this . buildPathPrefix ( end ) ) ;
135132 }
136133
137134 return paths ;
138135 }
139136
140137 private buildS3Query ( templateIds : string [ ] ) : string {
141- const likeConditions = templateIds
142- . map ( ( id ) => `s.Message LIKE '%${ id } %'` )
143- . join ( ' OR ' ) ;
138+ const formattedIds = templateIds . map ( ( r ) => `'${ r } '` ) ;
144139
145- return `SELECT * FROM S3Object s WHERE ${ likeConditions } ` ;
140+ return `SELECT * FROM S3Object s WHERE s.data.id IN ( ${ formattedIds } ) ` ;
146141 }
147142
148- private getEventCachePrefix ( date : Date ) : string {
143+ private buildPathPrefix ( date : Date ) : string {
149144 return date
150145 . toISOString ( )
151146 . slice ( 0 , 13 )
0 commit comments