From 73c44622163de21ba6b6e0bc239467c5745173ab Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 16 Aug 2023 12:40:11 +0530 Subject: [PATCH] fix: query update --- .../postgresql/queries/GeneralQueries.java | 18 +++++++++--------- .../postgresql/test/ExceptionParsingTest.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java index e949bfcf..2f460910 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java @@ -929,7 +929,7 @@ public static AuthRecipeUserInfo[] getUsers(Start start, TenantIdentifier tenant }, result -> { List temp = new ArrayList<>(); while (result.next()) { - temp.add(new UserInfoPaginationResultHolder(result.getString("user_id"), + temp.add(new UserInfoPaginationResultHolder(result.getString("primary_or_recipe_user_id"), result.getString("recipe_id"))); } return temp; @@ -959,11 +959,11 @@ public static AuthRecipeUserInfo[] getUsers(Start start, TenantIdentifier tenant recipeIdCondition = recipeIdCondition + " AND"; } String timeJoinedOrderSymbol = timeJoinedOrder.equals("ASC") ? ">" : "<"; - String QUERY = "SELECT user_id, recipe_id FROM " + getConfig(start).getUsersTable() + " WHERE " + String QUERY = "SELECT primary_or_recipe_user_id, recipe_id FROM " + getConfig(start).getUsersTable() + " WHERE " + recipeIdCondition + " (time_joined " + timeJoinedOrderSymbol - + " ? OR (time_joined = ? AND user_id <= ?)) AND app_id = ? AND tenant_id = ?" + + " ? OR (time_joined = ? AND primary_or_recipe_user_id <= ?)) AND app_id = ? AND tenant_id = ?" + " ORDER BY time_joined " + timeJoinedOrder - + ", user_id DESC LIMIT ?"; + + ", primary_or_recipe_user_id DESC LIMIT ?"; usersFromQuery = execute(start, QUERY, pst -> { if (includeRecipeIds != null) { for (int i = 0; i < includeRecipeIds.length; i++) { @@ -981,19 +981,19 @@ public static AuthRecipeUserInfo[] getUsers(Start start, TenantIdentifier tenant }, result -> { List temp = new ArrayList<>(); while (result.next()) { - temp.add(new UserInfoPaginationResultHolder(result.getString("user_id"), + temp.add(new UserInfoPaginationResultHolder(result.getString("primary_or_recipe_user_id"), result.getString("recipe_id"))); } return temp; }); } else { String recipeIdCondition = RECIPE_ID_CONDITION.toString(); - String QUERY = "SELECT user_id, recipe_id FROM " + getConfig(start).getUsersTable() + " WHERE "; + String QUERY = "SELECT primary_or_recipe_user_id, recipe_id FROM " + getConfig(start).getUsersTable() + " WHERE "; if (!recipeIdCondition.equals("")) { QUERY += recipeIdCondition + " AND"; } QUERY += " app_id = ? AND tenant_id = ? ORDER BY time_joined " + timeJoinedOrder - + ", user_id DESC LIMIT ?"; + + ", primary_or_recipe_user_id DESC LIMIT ?"; usersFromQuery = execute(start, QUERY, pst -> { if (includeRecipeIds != null) { for (int i = 0; i < includeRecipeIds.length; i++) { @@ -1008,7 +1008,7 @@ public static AuthRecipeUserInfo[] getUsers(Start start, TenantIdentifier tenant }, result -> { List temp = new ArrayList<>(); while (result.next()) { - temp.add(new UserInfoPaginationResultHolder(result.getString("user_id"), + temp.add(new UserInfoPaginationResultHolder(result.getString("primary_or_recipe_user_id"), result.getString("recipe_id"))); } return temp; @@ -1179,7 +1179,7 @@ private static AuthRecipeUserInfo[] listPrimaryUsersByEmailHelper(Start start, C userIds); // this is going to order them based on oldest that joined to newest that joined. - result.sort(Comparator.comparingLong(o -> o.timeJoined)); + result.sort(Comparator.comparingLong(o -> o.timeJoined)); return result.toArray(new AuthRecipeUserInfo[0]); } diff --git a/src/test/java/io/supertokens/storage/postgresql/test/ExceptionParsingTest.java b/src/test/java/io/supertokens/storage/postgresql/test/ExceptionParsingTest.java index 6c14cffb..7fd988ac 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/ExceptionParsingTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/ExceptionParsingTest.java @@ -287,7 +287,7 @@ public void addPasswordResetTokenExceptions() throws Exception { String pwHash = "fakehash"; String userEmail = "useremail@asdf.fdas"; - var info = new PasswordResetTokenInfo(userId, tokenHash, System.currentTimeMillis() + 10000); + var info = new PasswordResetTokenInfo(userId, tokenHash, System.currentTimeMillis() + 10000, userEmail); try { storage.addPasswordResetToken(new AppIdentifier(null, null), info); } catch (UnknownUserIdException ex) {