diff --git a/CHANGELOG.md b/CHANGELOG.md index b105bb4f4..b4667106a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixes - Fixes issue with user id mapping while refreshing session +- Adds indexing for `session_info` table on `user_id, app_id` columns ### Migrations @@ -54,6 +55,8 @@ CREATE INDEX IF NOT EXISTS bulk_import_users_status_updated_at_index ON bulk_imp CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index1 ON bulk_import_users (app_id, status, created_at DESC, id DESC); CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index2 ON bulk_import_users (app_id, created_at DESC, id DESC); + +CREATE INDEX IF NOT EXISTS session_info_user_id_app_id_index ON session_info (user_id, app_id); ``` For MySQL run the following SQL script: @@ -77,6 +80,8 @@ CREATE INDEX bulk_import_users_status_updated_at_index ON bulk_import_users (app CREATE INDEX bulk_import_users_pagination_index1 ON bulk_import_users (app_id, status, created_at DESC, id DESC); CREATE INDEX bulk_import_users_pagination_index2 ON bulk_import_users (app_id, created_at DESC, id DESC); + +CREATE INDEX session_info_user_id_app_id_index ON session_info (user_id, app_id); ``` ## [9.3.1] diff --git a/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java index 400618dd8..b6dc4434b 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java @@ -258,6 +258,7 @@ public static void createTablesIfNotExists(Start start, Main main) throws SQLExc // index update(start, getQueryToCreateSessionExpiryIndex(start), NO_OP_SETTER); + update(start, getQueryToCreateSessionAppIdUserIdIndex(start), NO_OP_SETTER); } if (!doesTableExists(start, Config.getConfig(start).getTenantConfigsTable())) { diff --git a/src/main/java/io/supertokens/inmemorydb/queries/SessionQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/SessionQueries.java index 61560127a..d995ce28a 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/SessionQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/SessionQueries.java @@ -76,6 +76,11 @@ static String getQueryToCreateSessionExpiryIndex(Start start) { + Config.getConfig(start).getSessionInfoTable() + "(expires_at);"; } + static String getQueryToCreateSessionAppIdUserIdIndex(Start start) { + return "CREATE INDEX session_info_user_id_app_id_index ON " + + Config.getConfig(start).getSessionInfoTable() + "(user_id, app_id);"; + } + public static void createNewSession(Start start, TenantIdentifier tenantIdentifier, String sessionHandle, String userId, String refreshTokenHash2, JsonObject userDataInDatabase, long expiry, JsonObject userDataInJWT,