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

fix: indexes for better getUserById queries #84

Merged
merged 7 commits into from
Nov 28, 2023
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
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
Loading