@@ -265,20 +265,44 @@ public static List<String> isEmailVerified_transaction(Start start, Connection s
265
265
emails .add (ue .email );
266
266
userIds .add (ue .userId );
267
267
}
268
+
269
+ // We have external user id stored in the email verification table, so we need to fetch the mapped userids for
270
+ // calculating the verified emails
271
+
272
+ HashMap <String , String > userIdMappings = UserIdMappingQueries .getUserIdMappingWithUserIds_Transaction (start ,
273
+ sqlCon , userIds );
274
+ HashMap <String , String > externalUserIdMappings = new HashMap <>();
275
+
276
+ List <String > userIdsToQuery = new ArrayList <>();
277
+ for (String userId : userIds ) {
278
+ if (userIdMappings .containsKey (userId )) {
279
+ userIdsToQuery .add (userIdMappings .get (userId ));
280
+ externalUserIdMappings .put (userIdMappings .get (userId ), userId );
281
+ } else {
282
+ userIdsToQuery .add (userId );
283
+ externalUserIdMappings .put (userId , userId );
284
+ }
285
+ }
286
+
268
287
for (UserIdAndEmail ue : userIdAndEmail ) {
269
- if (userIdToEmailMap .containsKey (ue .userId )) {
288
+ String userId = ue .userId ;
289
+ if (userIdMappings .containsKey (userId )) {
290
+ userId = userIdMappings .get (userId );
291
+ }
292
+ if (userIdToEmailMap .containsKey (userId )) {
270
293
throw new RuntimeException ("Found a bug!" );
271
294
}
272
- userIdToEmailMap .put (ue . userId , ue .email );
295
+ userIdToEmailMap .put (userId , ue .email );
273
296
}
297
+
274
298
String QUERY = "SELECT * FROM " + getConfig (start ).getEmailVerificationTable ()
275
- + " WHERE app_id = ? AND user_id IN (" + Utils .generateCommaSeperatedQuestionMarks (userIds .size ()) +
299
+ + " WHERE app_id = ? AND user_id IN (" + Utils .generateCommaSeperatedQuestionMarks (userIdsToQuery .size ()) +
276
300
") AND email IN (" + Utils .generateCommaSeperatedQuestionMarks (emails .size ()) + ")" ;
277
301
278
302
return execute (sqlCon , QUERY , pst -> {
279
303
pst .setString (1 , appIdentifier .getAppId ());
280
304
int index = 2 ;
281
- for (String userId : userIds ) {
305
+ for (String userId : userIdsToQuery ) {
282
306
pst .setString (index ++, userId );
283
307
}
284
308
for (String email : emails ) {
@@ -290,7 +314,7 @@ public static List<String> isEmailVerified_transaction(Start start, Connection s
290
314
String userId = result .getString ("user_id" );
291
315
String email = result .getString ("email" );
292
316
if (Objects .equals (userIdToEmailMap .get (userId ), email )) {
293
- res .add (userId );
317
+ res .add (externalUserIdMappings . get ( userId ) );
294
318
}
295
319
}
296
320
return res ;
@@ -310,11 +334,34 @@ public static List<String> isEmailVerified(Start start, AppIdentifier appIdentif
310
334
emails .add (ue .email );
311
335
userIds .add (ue .userId );
312
336
}
337
+
338
+ // We have external user id stored in the email verification table, so we need to fetch the mapped userids for
339
+ // calculating the verified emails
340
+
341
+ HashMap <String , String > userIdMappings = UserIdMappingQueries .getUserIdMappingWithUserIds (start ,
342
+ userIds );
343
+ HashMap <String , String > externalUserIdMappings = new HashMap <>();
344
+
345
+ List <String > userIdsToQuery = new ArrayList <>();
346
+ for (String userId : userIds ) {
347
+ if (userIdMappings .containsKey (userId )) {
348
+ userIdsToQuery .add (userIdMappings .get (userId ));
349
+ externalUserIdMappings .put (userIdMappings .get (userId ), userId );
350
+ } else {
351
+ userIdsToQuery .add (userId );
352
+ externalUserIdMappings .put (userId , userId );
353
+ }
354
+ }
355
+
313
356
for (UserIdAndEmail ue : userIdAndEmail ) {
314
- if (userIdToEmailMap .containsKey (ue .userId )) {
357
+ String userId = ue .userId ;
358
+ if (userIdMappings .containsKey (userId )) {
359
+ userId = userIdMappings .get (userId );
360
+ }
361
+ if (userIdToEmailMap .containsKey (userId )) {
315
362
throw new RuntimeException ("Found a bug!" );
316
363
}
317
- userIdToEmailMap .put (ue . userId , ue .email );
364
+ userIdToEmailMap .put (userId , ue .email );
318
365
}
319
366
String QUERY = "SELECT * FROM " + getConfig (start ).getEmailVerificationTable ()
320
367
+ " WHERE app_id = ? AND user_id IN (" + Utils .generateCommaSeperatedQuestionMarks (userIds .size ()) +
@@ -323,7 +370,7 @@ public static List<String> isEmailVerified(Start start, AppIdentifier appIdentif
323
370
return execute (start , QUERY , pst -> {
324
371
pst .setString (1 , appIdentifier .getAppId ());
325
372
int index = 2 ;
326
- for (String userId : userIds ) {
373
+ for (String userId : userIdsToQuery ) {
327
374
pst .setString (index ++, userId );
328
375
}
329
376
for (String email : emails ) {
@@ -335,7 +382,7 @@ public static List<String> isEmailVerified(Start start, AppIdentifier appIdentif
335
382
String userId = result .getString ("user_id" );
336
383
String email = result .getString ("email" );
337
384
if (Objects .equals (userIdToEmailMap .get (userId ), email )) {
338
- res .add (userId );
385
+ res .add (externalUserIdMappings . get ( userId ) );
339
386
}
340
387
}
341
388
return res ;
0 commit comments