Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Optimize getUserIdMappingWithEitherSuperTokensUserIdOrExternalUserId query #1095

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading