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: index updates #152

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,44 @@ public static String getQueryToCreateTenantIdIndexForUsersTable(Start start) {
+ Config.getConfig(start).getUsersTable() + "(app_id, tenant_id);";
}

static String getQueryToCreateUserPaginationIndex(Start start) {
return "CREATE INDEX all_auth_recipe_users_pagination_index ON " + Config.getConfig(start).getUsersTable()
+ "(primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC, tenant_id DESC, app_id DESC);";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add psql prs to this checklist: supertokens/supertokens-core#742 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

static String getQueryToCreateUserPaginationIndex1(Start start) {
return "CREATE INDEX all_auth_recipe_users_pagination_index1 ON " + Config.getConfig(start).getUsersTable()
+ "(app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the changelog

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

static String getQueryToCreatePrimaryUserIdIndex(Start start) {
static String getQueryToCreateUserPaginationIndex2(Start start) {
return "CREATE INDEX all_auth_recipe_users_pagination_index2 ON " + Config.getConfig(start).getUsersTable()
+ "(app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);";
}

static String getQueryToCreateUserPaginationIndex3(Start start) {
return "CREATE INDEX all_auth_recipe_users_pagination_index3 ON " + Config.getConfig(start).getUsersTable()
+ "(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);";
}

static String getQueryToCreateUserPaginationIndex4(Start start) {
return "CREATE INDEX all_auth_recipe_users_pagination_index4 ON " + Config.getConfig(start).getUsersTable()
+ "(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);";
}

static String getQueryToCreatePrimaryUserIdAndTenantIndex(Start start) {
/*
* Used in:
* - does user exist
*
* */
return "CREATE INDEX all_auth_recipe_users_primary_user_id_index ON " + Config.getConfig(start).getUsersTable()
+ "(app_id, primary_or_recipe_user_id);";
return "CREATE INDEX all_auth_recipe_users_primary_user_id_and_tenant_id_index ON " +
Config.getConfig(start).getUsersTable()
+ "(primary_or_recipe_user_id, app_id);";
}

static String getQueryToCreatePrimaryUserIdAndTenantIndex(Start start) {
static String getQueryToCreateRecipeIdIndex(Start start) {
/*
* Used in:
* - user count query
*
* */
return "CREATE INDEX all_auth_recipe_users_primary_user_id_and_tenant_id_index ON " +
return "CREATE INDEX all_auth_recipe_users_recipe_id_index ON " +
Config.getConfig(start).getUsersTable()
+ "(app_id, tenant_id, primary_or_recipe_user_id);";
+ "(recipe_id, app_id, tenant_id);";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ "(recipe_id, app_id, tenant_id);";
+ "(app_id, recipe_id, tenant_id);";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

private static String getQueryToCreateAppsTable(Start start) {
Expand Down Expand Up @@ -249,9 +263,12 @@ public static void createTablesIfNotExists(Start start) throws SQLException, Sto
update(start, getQueryToCreateUsersTable(start), NO_OP_SETTER);

// index
update(start, getQueryToCreatePrimaryUserIdIndex(start), NO_OP_SETTER);
update(start, getQueryToCreateUserPaginationIndex(start), NO_OP_SETTER);
update(start, getQueryToCreateUserPaginationIndex1(start), NO_OP_SETTER);
update(start, getQueryToCreateUserPaginationIndex2(start), NO_OP_SETTER);
update(start, getQueryToCreateUserPaginationIndex3(start), NO_OP_SETTER);
update(start, getQueryToCreateUserPaginationIndex4(start), NO_OP_SETTER);
update(start, getQueryToCreatePrimaryUserIdAndTenantIndex(start), NO_OP_SETTER);
update(start, getQueryToCreateRecipeIdIndex(start), NO_OP_SETTER);
}

if (!doesTableExists(start, Config.getConfig(start).getUserLastActiveTable())) {
Expand Down
Loading