|
26 | 26 | import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; |
27 | 27 | import io.supertokens.pluginInterface.multitenancy.AppIdentifier; |
28 | 28 | import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; |
| 29 | +import io.supertokens.storage.postgresql.PreparedStatementValueSetter; |
29 | 30 | import io.supertokens.storage.postgresql.Start; |
30 | 31 | import io.supertokens.storage.postgresql.config.Config; |
31 | 32 | import io.supertokens.storage.postgresql.utils.Utils; |
32 | 33 |
|
33 | 34 | import java.sql.Connection; |
34 | | -import java.sql.PreparedStatement; |
35 | 35 | import java.sql.ResultSet; |
36 | 36 | import java.sql.SQLException; |
37 | 37 | import java.util.*; |
38 | 38 | import java.util.stream.Collectors; |
39 | 39 |
|
40 | 40 | import static io.supertokens.pluginInterface.RECIPE_ID.EMAIL_PASSWORD; |
41 | | -import static io.supertokens.storage.postgresql.QueryExecutorTemplate.execute; |
42 | | -import static io.supertokens.storage.postgresql.QueryExecutorTemplate.update; |
| 41 | +import static io.supertokens.storage.postgresql.QueryExecutorTemplate.*; |
43 | 42 | import static io.supertokens.storage.postgresql.config.Config.getConfig; |
44 | 43 | import static java.lang.System.currentTimeMillis; |
45 | 44 |
|
@@ -354,59 +353,52 @@ public static void signUpMultipleForBulkImport_Transaction(Start start, Connecti |
354 | 353 | "INSERT INTO " + getConfig(start).getEmailPasswordUserToTenantTable() |
355 | 354 | + "(app_id, tenant_id, user_id, email)" + " VALUES(?, ?, ?, ?)"; |
356 | 355 |
|
357 | | - PreparedStatement appIdToUserId = sqlCon.prepareStatement(app_id_to_user_id_QUERY); |
358 | | - PreparedStatement allAuthRecipeUsers = sqlCon.prepareStatement(all_auth_recipe_users_QUERY); |
359 | | - PreparedStatement emailPasswordUsers = sqlCon.prepareStatement(emailpassword_users_QUERY); |
360 | | - PreparedStatement emailPasswordUsersToTenant = sqlCon.prepareStatement(emailpassword_users_to_tenant_QUERY); |
| 356 | + List<PreparedStatementValueSetter> appIdToUserIdSetters = new ArrayList<>(); |
| 357 | + List<PreparedStatementValueSetter> allAuthRecipeUsersSetters = new ArrayList<>(); |
| 358 | + List<PreparedStatementValueSetter> emailPasswordUsersSetters = new ArrayList<>(); |
| 359 | + List<PreparedStatementValueSetter> emailPasswordUsersToTenantSetters = new ArrayList<>(); |
361 | 360 |
|
362 | | - int counter = 0; |
363 | 361 | for (EmailPasswordImportUser user : usersToSignUp) { |
364 | 362 | String userId = user.userId; |
365 | 363 | TenantIdentifier tenantIdentifier = user.tenantIdentifier; |
366 | 364 |
|
367 | | - appIdToUserId.setString(1, tenantIdentifier.getAppId()); |
368 | | - appIdToUserId.setString(2, userId); |
369 | | - appIdToUserId.setString(3, userId); |
370 | | - appIdToUserId.setString(4, EMAIL_PASSWORD.toString()); |
371 | | - appIdToUserId.addBatch(); |
372 | | - |
373 | | - |
374 | | - allAuthRecipeUsers.setString(1, tenantIdentifier.getAppId()); |
375 | | - allAuthRecipeUsers.setString(2, tenantIdentifier.getTenantId()); |
376 | | - allAuthRecipeUsers.setString(3, userId); |
377 | | - allAuthRecipeUsers.setString(4, userId); |
378 | | - allAuthRecipeUsers.setString(5, EMAIL_PASSWORD.toString()); |
379 | | - allAuthRecipeUsers.setLong(6, user.timeJoinedMSSinceEpoch); |
380 | | - allAuthRecipeUsers.setLong(7, user.timeJoinedMSSinceEpoch); |
381 | | - allAuthRecipeUsers.addBatch(); |
382 | | - |
383 | | - emailPasswordUsers.setString(1, tenantIdentifier.getAppId()); |
384 | | - emailPasswordUsers.setString(2, userId); |
385 | | - emailPasswordUsers.setString(3, user.email); |
386 | | - emailPasswordUsers.setString(4, user.passwordHash); |
387 | | - emailPasswordUsers.setLong(5, user.timeJoinedMSSinceEpoch); |
388 | | - emailPasswordUsers.addBatch(); |
389 | | - |
390 | | - emailPasswordUsersToTenant.setString(1, tenantIdentifier.getAppId()); |
391 | | - emailPasswordUsersToTenant.setString(2, tenantIdentifier.getTenantId()); |
392 | | - emailPasswordUsersToTenant.setString(3, userId); |
393 | | - emailPasswordUsersToTenant.setString(4, user.email); |
394 | | - emailPasswordUsersToTenant.addBatch(); |
395 | | - counter++; |
396 | | - if (counter % 100 == 0) { |
397 | | - appIdToUserId.executeBatch(); |
398 | | - allAuthRecipeUsers.executeBatch(); |
399 | | - emailPasswordUsers.executeBatch(); |
400 | | - emailPasswordUsersToTenant.executeBatch(); |
401 | | - } |
402 | | - } |
| 365 | + appIdToUserIdSetters.add(pst -> { |
| 366 | + pst.setString(1, tenantIdentifier.getAppId()); |
| 367 | + pst.setString(2, userId); |
| 368 | + pst.setString(3, userId); |
| 369 | + pst.setString(4, EMAIL_PASSWORD.toString()); |
| 370 | + }); |
| 371 | + |
| 372 | + allAuthRecipeUsersSetters.add(pst -> { |
| 373 | + pst.setString(1, tenantIdentifier.getAppId()); |
| 374 | + pst.setString(2, tenantIdentifier.getTenantId()); |
| 375 | + pst.setString(3, userId); |
| 376 | + pst.setString(4, userId); |
| 377 | + pst.setString(5, EMAIL_PASSWORD.toString()); |
| 378 | + pst.setLong(6, user.timeJoinedMSSinceEpoch); |
| 379 | + pst.setLong(7, user.timeJoinedMSSinceEpoch); |
| 380 | + }); |
403 | 381 |
|
404 | | - //execute the remaining ones |
405 | | - appIdToUserId.executeBatch(); |
406 | | - allAuthRecipeUsers.executeBatch(); |
407 | | - emailPasswordUsers.executeBatch(); |
408 | | - emailPasswordUsersToTenant.executeBatch(); |
| 382 | + emailPasswordUsersSetters.add(pst -> { |
| 383 | + pst.setString(1, tenantIdentifier.getAppId()); |
| 384 | + pst.setString(2, userId); |
| 385 | + pst.setString(3, user.email); |
| 386 | + pst.setString(4, user.passwordHash); |
| 387 | + pst.setLong(5, user.timeJoinedMSSinceEpoch); |
| 388 | + }); |
| 389 | + |
| 390 | + emailPasswordUsersToTenantSetters.add(pst -> { |
| 391 | + pst.setString(1, tenantIdentifier.getAppId()); |
| 392 | + pst.setString(2, tenantIdentifier.getTenantId()); |
| 393 | + pst.setString(3, userId); |
| 394 | + pst.setString(4, user.email); |
| 395 | + }); |
| 396 | + } |
409 | 397 |
|
| 398 | + executeBatch(sqlCon, app_id_to_user_id_QUERY, appIdToUserIdSetters); |
| 399 | + executeBatch(sqlCon, all_auth_recipe_users_QUERY, allAuthRecipeUsersSetters); |
| 400 | + executeBatch(sqlCon, emailpassword_users_QUERY, emailPasswordUsersSetters); |
| 401 | + executeBatch(sqlCon, emailpassword_users_to_tenant_QUERY, emailPasswordUsersToTenantSetters); |
410 | 402 | sqlCon.commit(); |
411 | 403 | } catch (SQLException throwables) { |
412 | 404 | throw new StorageTransactionLogicException(throwables); |
|
0 commit comments