Skip to content

Commit b83a780

Browse files
committed
chore: current state save
1 parent a6ed05f commit b83a780

File tree

4 files changed

+75
-45
lines changed

4 files changed

+75
-45
lines changed

src/main/java/io/supertokens/storage/postgresql/BulkImportProxyConnection.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,7 @@
1616

1717
package io.supertokens.storage.postgresql;
1818

19-
import java.sql.Array;
20-
import java.sql.Blob;
21-
import java.sql.CallableStatement;
22-
import java.sql.Clob;
23-
import java.sql.Connection;
24-
import java.sql.DatabaseMetaData;
25-
import java.sql.NClob;
26-
import java.sql.PreparedStatement;
27-
import java.sql.SQLClientInfoException;
28-
import java.sql.SQLException;
29-
import java.sql.SQLWarning;
30-
import java.sql.SQLXML;
31-
import java.sql.Savepoint;
32-
import java.sql.Statement;
33-
import java.sql.Struct;
19+
import java.sql.*;
3420
import java.util.Map;
3521
import java.util.Properties;
3622
import java.util.concurrent.Executor;
@@ -53,17 +39,17 @@ public BulkImportProxyConnection(Connection con) {
5339

5440
@Override
5541
public void close() throws SQLException {
56-
// We simply ignore when close is called BulkImportProxyConnection
42+
// this.con.close();
5743
}
5844

5945
@Override
6046
public void commit() throws SQLException {
61-
// We simply ignore when commit is called BulkImportProxyConnection
47+
// this.con.commit();
6248
}
6349

6450
@Override
6551
public void rollback() throws SQLException {
66-
// We simply ignore when rollback is called BulkImportProxyConnection
52+
// this.con.rollback();
6753
}
6854

6955
public void closeForBulkImportProxyStorage() throws SQLException {

src/main/java/io/supertokens/storage/postgresql/BulkImportProxyStorage.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@
1616

1717
package io.supertokens.storage.postgresql;
1818

19-
import java.sql.Connection;
20-
import java.sql.SQLException;
21-
import java.util.List;
22-
import java.util.Set;
23-
24-
import com.google.gson.JsonObject;
25-
26-
import io.supertokens.pluginInterface.LOG_LEVEL;
2719
import io.supertokens.pluginInterface.exceptions.DbInitException;
28-
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
2920
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
3021
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
3122
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
3223
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
3324

25+
import java.sql.Connection;
26+
import java.sql.SQLException;
27+
import java.util.List;
28+
3429

3530
/**
3631
* BulkImportProxyStorage is a class extending Start, serving as a Storage instance in the bulk import user cronjob.
@@ -62,8 +57,9 @@ protected <T> T startTransactionHelper(TransactionLogic<T> logic, TransactionIso
6257

6358
@Override
6459
public void commitTransaction(TransactionConnection con) throws StorageQueryException {
65-
// We do not want to commit the queries when using the BulkImportProxyStorage to be able to rollback everything
60+
// We do not want to commit the queries when using the BulkImportProxyStorage to be able to rollback everything
6661
// if any query fails while importing the user
62+
// super.commitTransaction(con);
6763
}
6864

6965
@Override
@@ -114,4 +110,12 @@ public void rollbackTransactionForBulkImportProxyStorage() throws StorageQueryEx
114110
throw new StorageQueryException(e);
115111
}
116112
}
113+
114+
public void doVacuumFull() throws StorageQueryException {
115+
try {
116+
this.connection.prepareStatement("VACUUM FULL").execute();
117+
} catch (SQLException e) {
118+
throw new StorageQueryException(e);
119+
}
120+
}
117121
}

src/main/java/io/supertokens/storage/postgresql/Start.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
import io.supertokens.pluginInterface.authRecipe.LoginMethod;
2727
import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage;
2828
import io.supertokens.pluginInterface.bulkimport.BulkImportStorage;
29-
import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BULK_IMPORT_USER_STATUS;
29+
import io.supertokens.pluginInterface.bulkimport.BulkImportUser;
3030
import io.supertokens.pluginInterface.bulkimport.exceptions.BulkImportTransactionRolledBackException;
3131
import io.supertokens.pluginInterface.bulkimport.sqlStorage.BulkImportSQLStorage;
32-
import io.supertokens.pluginInterface.bulkimport.BulkImportUser;
3332
import io.supertokens.pluginInterface.dashboard.DashboardSearchTags;
3433
import io.supertokens.pluginInterface.dashboard.DashboardSessionInfo;
3534
import io.supertokens.pluginInterface.dashboard.DashboardUser;
@@ -53,7 +52,10 @@
5352
import io.supertokens.pluginInterface.jwt.JWTSigningKeyInfo;
5453
import io.supertokens.pluginInterface.jwt.exceptions.DuplicateKeyIdException;
5554
import io.supertokens.pluginInterface.jwt.sqlstorage.JWTRecipeSQLStorage;
56-
import io.supertokens.pluginInterface.multitenancy.*;
55+
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
56+
import io.supertokens.pluginInterface.multitenancy.MultitenancyStorage;
57+
import io.supertokens.pluginInterface.multitenancy.TenantConfig;
58+
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
5759
import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateClientTypeException;
5860
import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateTenantException;
5961
import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateThirdPartyIdException;
@@ -103,7 +105,10 @@
103105
import java.sql.Connection;
104106
import java.sql.SQLException;
105107
import java.sql.SQLTransactionRollbackException;
106-
import java.util.*;
108+
import java.util.ArrayList;
109+
import java.util.HashMap;
110+
import java.util.List;
111+
import java.util.Set;
107112

108113
import static io.supertokens.storage.postgresql.QueryExecutorTemplate.execute;
109114

src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,16 @@ static String getQueryToCreateUsersTable(Start start) {
103103

104104
public static String getQueryToCreateUserIdIndexForUsersTable(Start start) {
105105
return "CREATE INDEX IF NOT EXISTS all_auth_recipe_user_id_index ON "
106+
+ Config.getConfig(start).getUsersTable() + "(user_id);";
107+
}
108+
public static String getQueryToCreateUserIdAppIdIndexForUsersTable(Start start) {
109+
return "CREATE INDEX IF NOT EXISTS all_auth_recipe_user_id_app_id_index ON "
106110
+ Config.getConfig(start).getUsersTable() + "(app_id, user_id);";
107111
}
112+
public static String getQueryToCreateAppIdIndexForUsersTable(Start start) {
113+
return "CREATE INDEX IF NOT EXISTS all_auth_recipe_user_app_id_index ON "
114+
+ Config.getConfig(start).getUsersTable() + "(app_id);";
115+
}
108116

109117
public static String getQueryToCreateTenantIdIndexForUsersTable(Start start) {
110118
return "CREATE INDEX IF NOT EXISTS all_auth_recipe_tenant_id_index ON "
@@ -247,6 +255,11 @@ static String getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable(Start star
247255
+ Config.getConfig(start).getAppIdToUserIdTable() + "(primary_or_recipe_user_id, app_id);";
248256
}
249257

258+
static String getQueryToCreateUserIdIndexForAppIdToUserIdTable(Start start) {
259+
return "CREATE INDEX IF NOT EXISTS app_id_to_user_id_user_id_index ON "
260+
+ Config.getConfig(start).getAppIdToUserIdTable() + "(user_id, app_id);";
261+
}
262+
250263
public static void createTablesIfNotExists(Start start, Connection con) throws SQLException, StorageQueryException {
251264
int numberOfRetries = 0;
252265
boolean retry = true;
@@ -281,6 +294,7 @@ public static void createTablesIfNotExists(Start start, Connection con) throws S
281294
// index
282295
update(con, getQueryToCreateAppIdIndexForAppIdToUserIdTable(start), NO_OP_SETTER);
283296
update(con, getQueryToCreatePrimaryUserIdIndexForAppIdToUserIdTable(start), NO_OP_SETTER);
297+
update(con, getQueryToCreateUserIdIndexForAppIdToUserIdTable(start), NO_OP_SETTER);
284298
}
285299

286300
if (!doesTableExists(start, con, Config.getConfig(start).getUsersTable())) {
@@ -433,6 +447,8 @@ public static void createTablesIfNotExists(Start start, Connection con) throws S
433447

434448
// index
435449
update(con, getQueryToCreateUserIdIndexForUsersTable(start), NO_OP_SETTER);
450+
update(con, getQueryToCreateUserIdAppIdIndexForUsersTable(start), NO_OP_SETTER);
451+
update(con, getQueryToCreateAppIdIndexForUsersTable(start), NO_OP_SETTER);
436452
update(con, getQueryToCreateTenantIdIndexForUsersTable(start), NO_OP_SETTER);
437453
}
438454

@@ -1534,18 +1550,37 @@ private static List<AuthRecipeUserInfo> getPrimaryUserInfoForUserIds_Transaction
15341550
// which is linked to a primary user ID in which case it won't be in the primary_or_recipe_user_id column,
15351551
// or the input may have a primary user ID whose recipe user ID was removed, so it won't be in the user_id
15361552
// column
1537-
String QUERY =
1538-
"SELECT au.user_id, au.primary_or_recipe_user_id, au.is_linked_or_is_a_primary_user, au.recipe_id, " +
1539-
"aaru.tenant_id, aaru.time_joined FROM " +
1540-
getConfig(start).getAppIdToUserIdTable() + " as au" +
1541-
" LEFT JOIN " + getConfig(start).getUsersTable() +
1542-
" as aaru ON au.app_id = aaru.app_id AND au.user_id = aaru.user_id" +
1543-
" WHERE au.primary_or_recipe_user_id IN (SELECT primary_or_recipe_user_id FROM " +
1544-
getConfig(start).getAppIdToUserIdTable() + " WHERE (user_id IN ("
1545-
+ Utils.generateCommaSeperatedQuestionMarks(userIds.size()) +
1546-
") OR primary_or_recipe_user_id IN (" +
1547-
Utils.generateCommaSeperatedQuestionMarks(userIds.size()) +
1548-
")) AND app_id = ?) AND au.app_id = ?";
1553+
// String QUERY =
1554+
// "SELECT au.user_id, au.primary_or_recipe_user_id, au.is_linked_or_is_a_primary_user, au.recipe_id, " +
1555+
// "aaru.tenant_id, aaru.time_joined " +
1556+
// "FROM " + getConfig(start).getAppIdToUserIdTable() + " as au" +
1557+
// " LEFT JOIN " + getConfig(start).getUsersTable() +
1558+
// " as aaru ON au.app_id = aaru.app_id AND au.user_id = aaru.user_id" +
1559+
// " WHERE au.primary_or_recipe_user_id IN " +
1560+
// " (SELECT primary_or_recipe_user_id FROM " +
1561+
// getConfig(start).getAppIdToUserIdTable() +
1562+
// " WHERE (user_id IN ("
1563+
// + Utils.generateCommaSeperatedQuestionMarks(userIds.size()) +") " +
1564+
// " OR primary_or_recipe_user_id IN (" + Utils.generateCommaSeperatedQuestionMarks(userIds.size()) +")) " +
1565+
// " AND app_id = ?) " +
1566+
// "AND au.app_id = ?";
1567+
1568+
String QUERY = "SELECT" +
1569+
" au.user_id," +
1570+
" au.primary_or_recipe_user_id," +
1571+
" au.is_linked_or_is_a_primary_user," +
1572+
" au.recipe_id," +
1573+
" aaru.tenant_id," +
1574+
" aaru.time_joined" +
1575+
" FROM " + getConfig(start).getAppIdToUserIdTable() + " as au" +
1576+
" LEFT JOIN " + getConfig(start).getUsersTable() + " as aaru ON au.app_id = aaru.app_id" +
1577+
" AND au.user_id = aaru.user_id" +
1578+
" LEFT JOIN " + getConfig(start).getAppIdToUserIdTable() + " as aiui ON au.primary_or_recipe_user_id = aiui.user_id" +
1579+
" AND aiui.app_id = au.app_id" +
1580+
" WHERE" +
1581+
" aiui.user_id IN (" + Utils.generateCommaSeperatedQuestionMarks(userIds.size()) + ")" +
1582+
" OR au.primary_or_recipe_user_id IN ("+ Utils.generateCommaSeperatedQuestionMarks(userIds.size()) +")" +
1583+
" AND au.app_id = ?";
15491584

15501585
List<AllAuthRecipeUsersResultHolder> allAuthUsersResult = execute(sqlCon, QUERY, pst -> {
15511586
// IN user_id
@@ -1559,7 +1594,7 @@ private static List<AuthRecipeUserInfo> getPrimaryUserInfoForUserIds_Transaction
15591594
}
15601595
// for app_id
15611596
pst.setString(index, appIdentifier.getAppId());
1562-
pst.setString(index + 1, appIdentifier.getAppId());
1597+
// System.out.println(pst);
15631598
}, result -> {
15641599
List<AllAuthRecipeUsersResultHolder> parsedResult = new ArrayList<>();
15651600
while (result.next()) {

0 commit comments

Comments
 (0)