Skip to content

Commit

Permalink
refactor: Optimize getUserIdMappingWithEitherSuperTokensUserIdOrExter…
Browse files Browse the repository at this point in the history
…nalUserId query (#144)

Co-authored-by: Sattvik Chakravarthy <[email protected]>
  • Loading branch information
mavwolverine and sattvikc authored Jan 8, 2025
1 parent d5c5ab8 commit 2b6db96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 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).

- Adds queries for Bulk Import
- Adds support for multithreaded bulk import
- Optimize getUserIdMappingWithEitherSuperTokensUserIdOrExternalUserId query

### Migration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,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 Down Expand Up @@ -364,12 +368,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 2b6db96

Please sign in to comment.