@@ -103,8 +103,16 @@ static String getQueryToCreateUsersTable(Start start) {
103103
104104 public static String getQueryToCreateUserIdIndexForUsersTable (Start start ) {
105105 return "CREATE INDEX IF NOT EXISTS all_auth_recipe_user_id_index ON "
106+ + Config .getConfig (start ).getUsersTable () + "(user_id);" ;
107+ }
108+ public static String getQueryToCreateUserIdAppIdIndexForUsersTable (Start start ) {
109+ return "CREATE INDEX IF NOT EXISTS all_auth_recipe_user_id_app_id_index ON "
106110 + Config .getConfig (start ).getUsersTable () + "(app_id, user_id);" ;
107111 }
112+ public static String getQueryToCreateAppIdIndexForUsersTable (Start start ) {
113+ return "CREATE INDEX IF NOT EXISTS all_auth_recipe_user_app_id_index ON "
114+ + Config .getConfig (start ).getUsersTable () + "(app_id);" ;
115+ }
108116
109117 public static String getQueryToCreateTenantIdIndexForUsersTable (Start start ) {
110118 return "CREATE INDEX IF NOT EXISTS all_auth_recipe_tenant_id_index ON "
@@ -247,6 +255,11 @@ static String getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable(Start star
247255 + Config .getConfig (start ).getAppIdToUserIdTable () + "(primary_or_recipe_user_id, app_id);" ;
248256 }
249257
258+ static String getQueryToCreateUserIdIndexForAppIdToUserIdTable (Start start ) {
259+ return "CREATE INDEX IF NOT EXISTS app_id_to_user_id_user_id_index ON "
260+ + Config .getConfig (start ).getAppIdToUserIdTable () + "(user_id, app_id);" ;
261+ }
262+
250263 public static void createTablesIfNotExists (Start start , Connection con ) throws SQLException , StorageQueryException {
251264 int numberOfRetries = 0 ;
252265 boolean retry = true ;
@@ -281,6 +294,7 @@ public static void createTablesIfNotExists(Start start, Connection con) throws S
281294 // index
282295 update (con , getQueryToCreateAppIdIndexForAppIdToUserIdTable (start ), NO_OP_SETTER );
283296 update (con , getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable (start ), NO_OP_SETTER );
297+ update (con , getQueryToCreateUserIdIndexForAppIdToUserIdTable (start ), NO_OP_SETTER );
284298 }
285299
286300 if (!doesTableExists (start , con , Config .getConfig (start ).getUsersTable ())) {
@@ -433,6 +447,8 @@ public static void createTablesIfNotExists(Start start, Connection con) throws S
433447
434448 // index
435449 update (con , getQueryToCreateUserIdIndexForUsersTable (start ), NO_OP_SETTER );
450+ update (con , getQueryToCreateUserIdAppIdIndexForUsersTable (start ), NO_OP_SETTER );
451+ update (con , getQueryToCreateAppIdIndexForUsersTable (start ), NO_OP_SETTER );
436452 update (con , getQueryToCreateTenantIdIndexForUsersTable (start ), NO_OP_SETTER );
437453 }
438454
@@ -1534,18 +1550,37 @@ private static List<AuthRecipeUserInfo> getPrimaryUserInfoForUserIds_Transaction
15341550 // which is linked to a primary user ID in which case it won't be in the primary_or_recipe_user_id column,
15351551 // or the input may have a primary user ID whose recipe user ID was removed, so it won't be in the user_id
15361552 // column
1537- String QUERY =
1538- "SELECT au.user_id, au.primary_or_recipe_user_id, au.is_linked_or_is_a_primary_user, au.recipe_id, " +
1539- "aaru.tenant_id, aaru.time_joined FROM " +
1540- getConfig (start ).getAppIdToUserIdTable () + " as au" +
1541- " LEFT JOIN " + getConfig (start ).getUsersTable () +
1542- " as aaru ON au.app_id = aaru.app_id AND au.user_id = aaru.user_id" +
1543- " WHERE au.primary_or_recipe_user_id IN (SELECT primary_or_recipe_user_id FROM " +
1544- getConfig (start ).getAppIdToUserIdTable () + " WHERE (user_id IN ("
1545- + Utils .generateCommaSeperatedQuestionMarks (userIds .size ()) +
1546- ") OR primary_or_recipe_user_id IN (" +
1547- Utils .generateCommaSeperatedQuestionMarks (userIds .size ()) +
1548- ")) AND app_id = ?) AND au.app_id = ?" ;
1553+ // String QUERY =
1554+ // "SELECT au.user_id, au.primary_or_recipe_user_id, au.is_linked_or_is_a_primary_user, au.recipe_id, " +
1555+ // "aaru.tenant_id, aaru.time_joined " +
1556+ // "FROM " + getConfig(start).getAppIdToUserIdTable() + " as au" +
1557+ // " LEFT JOIN " + getConfig(start).getUsersTable() +
1558+ // " as aaru ON au.app_id = aaru.app_id AND au.user_id = aaru.user_id" +
1559+ // " WHERE au.primary_or_recipe_user_id IN " +
1560+ // " (SELECT primary_or_recipe_user_id FROM " +
1561+ // getConfig(start).getAppIdToUserIdTable() +
1562+ // " WHERE (user_id IN ("
1563+ // + Utils.generateCommaSeperatedQuestionMarks(userIds.size()) +") " +
1564+ // " OR primary_or_recipe_user_id IN (" + Utils.generateCommaSeperatedQuestionMarks(userIds.size()) +")) " +
1565+ // " AND app_id = ?) " +
1566+ // "AND au.app_id = ?";
1567+
1568+ String QUERY = "SELECT" +
1569+ " au.user_id," +
1570+ " au.primary_or_recipe_user_id," +
1571+ " au.is_linked_or_is_a_primary_user," +
1572+ " au.recipe_id," +
1573+ " aaru.tenant_id," +
1574+ " aaru.time_joined" +
1575+ " FROM " + getConfig (start ).getAppIdToUserIdTable () + " as au" +
1576+ " LEFT JOIN " + getConfig (start ).getUsersTable () + " as aaru ON au.app_id = aaru.app_id" +
1577+ " AND au.user_id = aaru.user_id" +
1578+ " LEFT JOIN " + getConfig (start ).getAppIdToUserIdTable () + " as aiui ON au.primary_or_recipe_user_id = aiui.user_id" +
1579+ " AND aiui.app_id = au.app_id" +
1580+ " WHERE" +
1581+ " aiui.user_id IN (" + Utils .generateCommaSeperatedQuestionMarks (userIds .size ()) + ")" +
1582+ " OR au.primary_or_recipe_user_id IN (" + Utils .generateCommaSeperatedQuestionMarks (userIds .size ()) +")" +
1583+ " AND au.app_id = ?" ;
15491584
15501585 List <AllAuthRecipeUsersResultHolder > allAuthUsersResult = execute (sqlCon , QUERY , pst -> {
15511586 // IN user_id
@@ -1559,7 +1594,7 @@ private static List<AuthRecipeUserInfo> getPrimaryUserInfoForUserIds_Transaction
15591594 }
15601595 // for app_id
15611596 pst .setString (index , appIdentifier .getAppId ());
1562- pst . setString ( index + 1 , appIdentifier . getAppId () );
1597+ // System.out.println(pst );
15631598 }, result -> {
15641599 List <AllAuthRecipeUsersResultHolder > parsedResult = new ArrayList <>();
15651600 while (result .next ()) {
0 commit comments