Skip to content

Commit

Permalink
fix: indexes for better getUserById queries (#84)
Browse files Browse the repository at this point in the history
* fix: transaction

* fix: index

* fix: index

* fix: version

* fix: revert query split

* fix: remove comments

* fix: changelog
  • Loading branch information
sattvikc authored Nov 28, 2023
1 parent bbc93ab commit 1d04eda
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [5.0.4] - 2023-11-10

- Adds index on `app_id_to_user_id` table to improve performance of get user by id queries
- Fixes call to `getPrimaryUserInfoForUserIds_Transaction` in `listPrimaryUsersByThirdPartyInfo_Transaction`

### Migration

Run the following SQL script:

```sql
CREATE INDEX app_id_to_user_id_primary_user_id_index ON app_id_to_user_id (primary_or_recipe_user_id);
CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
```

## [5.0.3] - 2023-11-10

- Fixes issue with email verification with user id mapping
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "5.0.3"
version = "5.0.4"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ private static String getQueryToCreateAppIdToUserIdTable(Start start) {
// @formatter:on
}

static String getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable(Start start) {
return "CREATE INDEX app_id_to_user_id_primary_user_id_index ON " +
Config.getConfig(start).getAppIdToUserIdTable()
+ "(primary_or_recipe_user_id);";
}

static String getQueryToCreateUserIdIndexForAppIdToUserIdTable(Start start) {
return "CREATE INDEX app_id_to_user_id_user_id_index ON " +
Config.getConfig(start).getAppIdToUserIdTable()
+ "(user_id);";
}

public static void createTablesIfNotExists(Start start) throws SQLException, StorageQueryException {
if (!doesTableExists(start, Config.getConfig(start).getAppsTable())) {
getInstance(start).addState(CREATING_NEW_TABLE, null);
Expand All @@ -210,6 +222,9 @@ public static void createTablesIfNotExists(Start start) throws SQLException, Sto
if (!doesTableExists(start, Config.getConfig(start).getAppIdToUserIdTable())) {
getInstance(start).addState(CREATING_NEW_TABLE, null);
update(start, getQueryToCreateAppIdToUserIdTable(start), NO_OP_SETTER);

update(start, getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable(start), NO_OP_SETTER);
update(start, getQueryToCreateUserIdIndexForAppIdToUserIdTable(start), NO_OP_SETTER);
}

if (!doesTableExists(start, Config.getConfig(start).getUsersTable())) {
Expand Down Expand Up @@ -1057,7 +1072,7 @@ public static AuthRecipeUserInfo[] listPrimaryUsersByEmail_Transaction(Start sta
Set<String> userIdsSet = new HashSet<>(userIds);
userIds = new ArrayList<>(userIdsSet);

List<AuthRecipeUserInfo> result = getPrimaryUserInfoForUserIds(start, appIdentifier,
List<AuthRecipeUserInfo> result = getPrimaryUserInfoForUserIds_Transaction(start, sqlCon, appIdentifier,
userIds);

// this is going to order them based on oldest that joined to newest that joined.
Expand Down

0 comments on commit 1d04eda

Please sign in to comment.