From ec29ca82495c36c5cacc47d0265e688d52a06044 Mon Sep 17 00:00:00 2001 From: tamassoltesz Date: Thu, 9 Jan 2025 21:15:08 +0100 Subject: [PATCH 1/2] fix: add index for session_info on user_id, app_id --- CHANGELOG.md | 14 ++++++++++++++ .../inmemorydb/queries/GeneralQueries.java | 1 + .../inmemorydb/queries/SessionQueries.java | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b105bb4f4..8328a6061 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,20 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Adds indexing for `session_info` table on `user_id, app_id` columns + +### Migration + +For PostgreSQL, run the following SQL script: +```sql +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: +```sql +CREATE INDEX session_info_user_id_app_id_index ON session_info (user_id, app_id); +``` + ## [9.4.0] ### Added 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, From d6c712ce02718309e758c73aeeab52d0de393a70 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 10 Jan 2025 12:26:40 +0530 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8328a6061..b4667106a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,20 +7,6 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -- Adds indexing for `session_info` table on `user_id, app_id` columns - -### Migration - -For PostgreSQL, run the following SQL script: -```sql -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: -```sql -CREATE INDEX session_info_user_id_app_id_index ON session_info (user_id, app_id); -``` - ## [9.4.0] ### Added @@ -44,6 +30,7 @@ CREATE INDEX session_info_user_id_app_id_index ON session_info (user_id, app_id) ### Fixes - Fixes issue with user id mapping while refreshing session +- Adds indexing for `session_info` table on `user_id, app_id` columns ### Migrations @@ -68,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: @@ -91,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]