Skip to content

Commit

Permalink
fix: index updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 14, 2023
1 parent 21e4ec9 commit f423a26
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,27 @@ 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);";
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);";
}

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 getQueryToCreatePrimaryUserId(Start start) {
/*
* Used in:
* - does user exist
Expand All @@ -110,15 +125,14 @@ static String getQueryToCreatePrimaryUserIdIndex(Start start) {
+ "(app_id, primary_or_recipe_user_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);";
+ "(app_id, recipe_id, tenant_id);";
}

private static String getQueryToCreateAppsTable(Start start) {
Expand Down Expand Up @@ -193,6 +207,8 @@ public static void createTablesIfNotExists(Start start, Main main) throws SQLExc
if (!doesTableExists(start, Config.getConfig(start).getKeyValueTable())) {
getInstance(main).addState(CREATING_NEW_TABLE, null);
update(start, getQueryToCreateKeyValueTable(start), NO_OP_SETTER);
// index
update(start, getQueryToCreateTenantIdIndexForKeyValueTable(start), NO_OP_SETTER);
}

if (!doesTableExists(start, Config.getConfig(start).getAppIdToUserIdTable())) {
Expand All @@ -205,9 +221,12 @@ public static void createTablesIfNotExists(Start start, Main main) throws SQLExc
update(start, getQueryToCreateUsersTable(start), NO_OP_SETTER);

// index
update(start, getQueryToCreatePrimaryUserIdIndex(start), NO_OP_SETTER);
update(start, getQueryToCreateUserPaginationIndex(start), NO_OP_SETTER);
update(start, getQueryToCreatePrimaryUserIdAndTenantIndex(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, getQueryToCreatePrimaryUserId(start), NO_OP_SETTER);
update(start, getQueryToCreateRecipeIdIndex(start), NO_OP_SETTER);
}

if (!doesTableExists(start, Config.getConfig(start).getUserLastActiveTable())) {
Expand Down Expand Up @@ -237,6 +256,7 @@ public static void createTablesIfNotExists(Start start, Main main) throws SQLExc
getInstance(main).addState(CREATING_NEW_TABLE, null);
update(start, MultitenancyQueries.getQueryToCreateTenantThirdPartyProvidersTable(start),
NO_OP_SETTER);

}

if (!doesTableExists(start, Config.getConfig(start).getTenantThirdPartyProviderClientsTable())) {
Expand Down Expand Up @@ -318,7 +338,6 @@ public static void createTablesIfNotExists(Start start, Main main) throws SQLExc
// index
update(start, getQueryToCreateCodeCreatedAtIndex(start), NO_OP_SETTER);
update(start, getQueryToCreateCodeDeviceIdHashIndex(start), NO_OP_SETTER);

}

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

0 comments on commit f423a26

Please sign in to comment.