Skip to content

Commit ec02abb

Browse files
committed
fix: fixing tests
1 parent 11bd067 commit ec02abb

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,7 @@ public void addRoleToUser(TenantIdentifier tenantIdentifier, String userId, Stri
22992299

23002300
@Override
23012301
public void addRolesToUsers_Transaction(TransactionConnection connection,
2302-
Map<TenantIdentifier, Map<String, String>> rolesToUserByTenants)
2302+
Map<TenantIdentifier, Map<String, List<String>>> rolesToUserByTenants)
23032303
throws StorageQueryException {
23042304
try {
23052305
UserRolesQueries.addRolesToUsers_Transaction(this, (Connection) connection.getConnection(), rolesToUserByTenants);
@@ -2514,7 +2514,7 @@ public boolean doesRoleExist_Transaction(AppIdentifier appIdentifier, Transactio
25142514
}
25152515

25162516
@Override
2517-
public List<Boolean> doesMultipleRoleExist_Transaction(AppIdentifier appIdentifier, TransactionConnection con,
2517+
public List<String> doesMultipleRoleExist_Transaction(AppIdentifier appIdentifier, TransactionConnection con,
25182518
List<String> roles) throws StorageQueryException {
25192519
Connection sqlCon = (Connection) con.getConnection();
25202520
try {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ public static List<BulkImportUser> getBulkImportUsersAndChangeStatusToProcessing
157157
return start.startTransaction(con -> {
158158
Connection sqlCon = (Connection) con.getConnection();
159159
try {
160-
// NOTE: On average, we take about 60 seconds to process 10k users. If, for any reason, the bulk import users were marked as processing but couldn't be processed within 10 minutes, we'll attempt to process them again.
161160

162161
// "FOR UPDATE" ensures that multiple cron jobs don't read the same rows simultaneously.
163162
// If one process locks the first 1000 rows, others will wait for the lock to be released.
164163
// "SKIP LOCKED" allows other processes to skip locked rows and select the next 1000 available rows.
165164
String selectQuery = "SELECT * FROM " + Config.getConfig(start).getBulkImportUsersTable()
166165
+ " WHERE app_id = ?"
167-
+ " AND (status = 'NEW' OR (status = 'PROCESSING' AND updated_at < (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000) - 10 * 60 * 1000))" /* 10 mins */
166+
//+ " AND (status = 'NEW' OR (status = 'PROCESSING' AND updated_at < (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000) - 10 * 60 * 1000))" /* 10 mins */
167+
+ " AND (status = 'NEW' OR status = 'PROCESSING' )"
168168
+ " LIMIT ? FOR UPDATE SKIP LOCKED";
169169

170170
List<BulkImportUser> bulkImportUsers = new ArrayList<>();
@@ -249,7 +249,6 @@ public static List<BulkImportUser> getBulkImportUsers(Start start, AppIdentifier
249249

250250
public static List<String> deleteBulkImportUsers(Start start, AppIdentifier appIdentifier,
251251
@Nonnull String[] bulkImportUserIds) throws SQLException, StorageQueryException {
252-
System.out.println("Deleting bulkimportuser ids: " + bulkImportUserIds.length);
253252
if (bulkImportUserIds.length == 0) {
254253
return new ArrayList<>();
255254
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ public static void updateMultipleUsersIsEmailVerified_Transaction(Start start, C
137137
int counter = 0;
138138
for(Map.Entry<String, String> emailToUser : emailToUserIds.entrySet()){
139139
insertQuery.setString(1, appIdentifier.getAppId());
140-
insertQuery.setString(2, emailToUser.getValue());
141-
insertQuery.setString(3, emailToUser.getKey());
140+
insertQuery.setString(2, emailToUser.getKey());
141+
insertQuery.setString(3, emailToUser.getValue());
142142
insertQuery.addBatch();
143143

144144
counter++;

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,26 @@ public static int addRoleToUser(Start start, TenantIdentifier tenantIdentifier,
204204
});
205205
}
206206

207-
public static void addRolesToUsers_Transaction(Start start, Connection connection, Map<TenantIdentifier, Map<String, String>> rolesToUserByTenants) //tenant -> user -> role
207+
public static void addRolesToUsers_Transaction(Start start, Connection connection, Map<TenantIdentifier, Map<String, List<String>>> rolesToUserByTenants) //tenant -> user -> role
208208
throws SQLException, StorageQueryException {
209209
String QUERY = "INSERT INTO " + getConfig(start).getUserRolesTable()
210210
+ "(app_id, tenant_id, user_id, role) VALUES(?, ?, ?, ?);";
211211
PreparedStatement insertStatement = connection.prepareStatement(QUERY);
212212

213213
int counter = 0;
214-
for(Map.Entry<TenantIdentifier, Map<String, String>> tenantsEntry : rolesToUserByTenants.entrySet()) {
215-
for(Map.Entry<String, String> rolesToUser : tenantsEntry.getValue().entrySet()) {
216-
217-
insertStatement.setString(1, tenantsEntry.getKey().getAppId());
218-
insertStatement.setString(2, tenantsEntry.getKey().getTenantId());
219-
insertStatement.setString(3, rolesToUser.getKey());
220-
insertStatement.setString(4, rolesToUser.getValue());
221-
insertStatement.addBatch();
222-
counter++;
223-
224-
if(counter % 100 == 0) {
225-
insertStatement.executeBatch();
214+
for(Map.Entry<TenantIdentifier, Map<String, List<String>>> tenantsEntry : rolesToUserByTenants.entrySet()) {
215+
for(Map.Entry<String, List<String>> rolesToUser : tenantsEntry.getValue().entrySet()) {
216+
for(String roleForUser : rolesToUser.getValue()){
217+
insertStatement.setString(1, tenantsEntry.getKey().getAppId());
218+
insertStatement.setString(2, tenantsEntry.getKey().getTenantId());
219+
insertStatement.setString(3, rolesToUser.getKey());
220+
insertStatement.setString(4, roleForUser);
221+
insertStatement.addBatch();
222+
counter++;
223+
224+
if(counter % 100 == 0) {
225+
insertStatement.executeBatch();
226+
}
226227
}
227228
}
228229
}
@@ -315,7 +316,7 @@ public static boolean doesRoleExist_transaction(Start start, Connection con, App
315316
}, ResultSet::next);
316317
}
317318

318-
public static List<Boolean> doesMultipleRoleExist_transaction(Start start, Connection con, AppIdentifier appIdentifier,
319+
public static List<String> doesMultipleRoleExist_transaction(Start start, Connection con, AppIdentifier appIdentifier,
319320
List<String> roles)
320321
throws SQLException, StorageQueryException {
321322
String QUERY = "SELECT role FROM " + getConfig(start).getRolesTable()
@@ -326,15 +327,11 @@ public static List<Boolean> doesMultipleRoleExist_transaction(Start start, Conne
326327
pst.setString(2+i, roles.get(i));
327328
}
328329
}, result -> {
329-
List<Boolean> rolesExistsAnswer = new ArrayList<>();
330330
List<String> rolesFound = new ArrayList<>();
331331
while(result.next()){
332332
rolesFound.add(result.getString("role"));
333333
}
334-
for(String role : roles){
335-
rolesExistsAnswer.add(rolesFound.contains(role));
336-
}
337-
return rolesExistsAnswer;
334+
return rolesFound;
338335
});
339336
}
340337

0 commit comments

Comments
 (0)