File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed
Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -208,20 +208,19 @@ export async function promoteUsersToNextTier(
208208 }
209209
210210 // Enroll every userId into a Firebase topic if they got promoted today
211- for ( const userId of userIds ) {
212- const { data : userDevice } = await SupabaseDB . NOTIFICATIONS . select (
213- "deviceId"
214- )
215- . eq ( "userId" , userId )
216- . maybeSingle ( )
217- . throwOnError ( ) ;
218- if ( ! userDevice ?. deviceId ) {
219- continue ; // we can just be done here if they don't have a deviceId
220- }
211+
212+ const { data : userDevices } = await SupabaseDB . NOTIFICATIONS . select (
213+ "deviceId"
214+ )
215+ . in ( "userId" , userIds )
216+ . throwOnError ( ) ;
217+
218+ if ( userDevices && userDevices . length > 0 ) {
219+ const deviceTokens = userDevices . map ( ( device ) => device . deviceId ) ;
221220 const topicName = `tier-promotion-${ day . toLowerCase ( ) } ` ;
222221 await getFirebaseAdmin ( )
223222 . messaging ( )
224- . subscribeToTopic ( userDevice . deviceId , topicName ) ;
223+ . subscribeToTopic ( deviceTokens , topicName ) ;
225224 }
226225
227226 return data || 0 ;
You can’t perform that action at this time.
0 commit comments