Skip to content

Commit

Permalink
Merge pull request #1095 from mavwolverine/master
Browse files Browse the repository at this point in the history
refactor: Optimize getUserIdMappingWithEitherSuperTokensUserIdOrExternalUserId query
  • Loading branch information
porcellus authored Jan 7, 2025
2 parents 95a0f11 + 0af2903 commit ccf6b49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Optimize getUserIdMappingWithEitherSuperTokensUserIdOrExternalUserId query
- Adds property `bulk_migration_parallelism` for fine-tuning the worker threads number
- Adds APIs to bulk import users
- GET `/bulk-import/users`
Expand Down Expand Up @@ -78,6 +79,7 @@ CREATE INDEX bulk_import_users_pagination_index2 ON bulk_import_users (app_id, c

- Includes exception class name in 500 error message


## [9.3.0]

### Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,16 @@ public static UserIdMapping[] getUserIdMappingWithEitherSuperTokensUserIdOrExter
String userId)
throws SQLException, StorageQueryException {
String QUERY = "SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable()
+ " WHERE app_id = ? AND (supertokens_user_id = ? OR external_user_id = ?)";
+ " WHERE app_id = ? AND supertokens_user_id = ?"
+ " UNION ALL "
+ "SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable()
+ " WHERE app_id = ? AND external_user_id = ?";

return execute(start, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
pst.setString(3, userId);
pst.setString(3, appIdentifier.getAppId());
pst.setString(4, userId);
}, result -> {
ArrayList<UserIdMapping> userIdMappingArray = new ArrayList<>();
while (result.next()) {
Expand All @@ -129,12 +133,16 @@ public static UserIdMapping[] getUserIdMappingWithEitherSuperTokensUserIdOrExter
String userId)
throws SQLException, StorageQueryException {
String QUERY = "SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable()
+ " WHERE app_id = ? AND (supertokens_user_id = ? OR external_user_id = ?)";
+ " WHERE app_id = ? AND supertokens_user_id = ?"
+ " UNION ALL "
+ "SELECT * FROM " + Config.getConfig(start).getUserIdMappingTable()
+ " WHERE app_id = ? AND external_user_id = ?";

return execute(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
pst.setString(3, userId);
pst.setString(3, appIdentifier.getAppId());
pst.setString(4, userId);
}, result -> {
ArrayList<UserIdMapping> userIdMappingArray = new ArrayList<>();
while (result.next()) {
Expand Down

0 comments on commit ccf6b49

Please sign in to comment.