Skip to content

Commit

Permalink
fix: add index for session_info on user_id, app_id (#1099)
Browse files Browse the repository at this point in the history
* fix: add index for session_info on user_id, app_id

* Update CHANGELOG.md

---------

Co-authored-by: Sattvik Chakravarthy <[email protected]>
  • Loading branch information
tamassoltesz and sattvikc authored Jan 10, 2025
1 parent 218789b commit 575e884
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 575e884

Please sign in to comment.