diff --git a/CHANGELOG.md b/CHANGELOG.md index 802c104..f676c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,20 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [5.0.4] - 2023-11-10 + +- Adds index on `app_id_to_user_id` table to improve performance of get user by id queries +- Fixes call to `getPrimaryUserInfoForUserIds_Transaction` in `listPrimaryUsersByThirdPartyInfo_Transaction` + +### Migration + +Run the following SQL script: + +```sql +CREATE INDEX app_id_to_user_id_primary_user_id_index ON app_id_to_user_id (primary_or_recipe_user_id); +CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id); +``` + ## [5.0.3] - 2023-11-10 - Fixes issue with email verification with user id mapping diff --git a/build.gradle b/build.gradle index 92cc3ea..33ccf53 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' } -version = "5.0.3" +version = "5.0.4" repositories { mavenCentral() diff --git a/src/main/java/io/supertokens/storage/mysql/queries/GeneralQueries.java b/src/main/java/io/supertokens/storage/mysql/queries/GeneralQueries.java index dffce2f..ba88f54 100644 --- a/src/main/java/io/supertokens/storage/mysql/queries/GeneralQueries.java +++ b/src/main/java/io/supertokens/storage/mysql/queries/GeneralQueries.java @@ -191,6 +191,18 @@ private static String getQueryToCreateAppIdToUserIdTable(Start start) { // @formatter:on } + static String getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable(Start start) { + return "CREATE INDEX app_id_to_user_id_primary_user_id_index ON " + + Config.getConfig(start).getAppIdToUserIdTable() + + "(primary_or_recipe_user_id);"; + } + + static String getQueryToCreateUserIdIndexForAppIdToUserIdTable(Start start) { + return "CREATE INDEX app_id_to_user_id_user_id_index ON " + + Config.getConfig(start).getAppIdToUserIdTable() + + "(user_id);"; + } + public static void createTablesIfNotExists(Start start) throws SQLException, StorageQueryException { if (!doesTableExists(start, Config.getConfig(start).getAppsTable())) { getInstance(start).addState(CREATING_NEW_TABLE, null); @@ -210,6 +222,9 @@ public static void createTablesIfNotExists(Start start) throws SQLException, Sto if (!doesTableExists(start, Config.getConfig(start).getAppIdToUserIdTable())) { getInstance(start).addState(CREATING_NEW_TABLE, null); update(start, getQueryToCreateAppIdToUserIdTable(start), NO_OP_SETTER); + + update(start, getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable(start), NO_OP_SETTER); + update(start, getQueryToCreateUserIdIndexForAppIdToUserIdTable(start), NO_OP_SETTER); } if (!doesTableExists(start, Config.getConfig(start).getUsersTable())) { @@ -1057,7 +1072,7 @@ public static AuthRecipeUserInfo[] listPrimaryUsersByEmail_Transaction(Start sta Set userIdsSet = new HashSet<>(userIds); userIds = new ArrayList<>(userIdsSet); - List result = getPrimaryUserInfoForUserIds(start, appIdentifier, + List result = getPrimaryUserInfoForUserIds_Transaction(start, sqlCon, appIdentifier, userIds); // this is going to order them based on oldest that joined to newest that joined.