Skip to content

Commit

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

Co-authored-by: Sattvik Chakravarthy <[email protected]>
  • Loading branch information
mavwolverine and sattvikc authored Jan 8, 2025
1 parent d5c06aa commit 194eb95
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 @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [7.3.0]

- Adds tables and queries for Bulk Import
- Optimize getUserIdMappingWithEitherSuperTokensUserIdOrExternalUserId query

### Migration

Expand All @@ -34,6 +35,7 @@ CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index1 ON bulk_import_us
CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index2 ON bulk_import_users (app_id, created_at DESC, id DESC);
```
## [7.2.0] - 2024-10-03
- Compatible with plugin interface version 6.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,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 @@ -375,12 +379,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 194eb95

Please sign in to comment.