Skip to content

Commit

Permalink
fix: cuds from db
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Feb 6, 2024
1 parent 98a9d3f commit f9a812d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ public class MultitenancyHelper extends ResourceDistributor.SingletonResource {
public static final String RESOURCE_KEY = "io.supertokens.multitenancy.Multitenancy";
private Main main;
private TenantConfig[] tenantConfigs;
private TenantConfig[] allTenantConfigsFromDbDangerous;

// when the core has `supertokens_saas_load_only_cud` set, the tenantConfigs array will be filtered
// based on the config value. However, we need to keep all the list of CUDs from the db to be able
// to check if the CUD is present in the DB or not, while processing the requests.
private final Set<String> dangerous_allCUDsFromDb = new HashSet<>();

private MultitenancyHelper(Main main) throws StorageQueryException {
this.main = main;
this.allTenantConfigsFromDbDangerous = getAllTenantsFromDb();
this.tenantConfigs = this.getFilteredTenantConfigs(this.allTenantConfigsFromDbDangerous);
TenantConfig[] allTenantsFromDb = getAllTenantsFromDb();
this.tenantConfigs = this.getFilteredTenantConfigs(allTenantsFromDb);
this.dangerous_allCUDsFromDb.clear();

for (TenantConfig config : allTenantsFromDb) {
this.dangerous_allCUDsFromDb.add(config.tenantIdentifier.getConnectionUriDomain());
}
}

public static MultitenancyHelper getInstance(Main main) {
Expand Down Expand Up @@ -135,7 +144,10 @@ public List<TenantIdentifier> refreshTenantsInCoreBasedOnChangesInCoreConfigOrIf
boolean sameNumberOfTenants =
filteredTenantsFromDb.length == this.tenantConfigs.length;

this.allTenantConfigsFromDbDangerous = tenantsFromDb;
this.dangerous_allCUDsFromDb.clear();
for (TenantConfig tenant : tenantsFromDb) {
this.dangerous_allCUDsFromDb.add(tenant.tenantIdentifier.getConnectionUriDomain());
}
this.tenantConfigs = filteredTenantsFromDb;
if (tenantsThatChanged.size() == 0 && sameNumberOfTenants) {
return tenantsThatChanged;
Expand Down Expand Up @@ -258,12 +270,6 @@ private TenantConfig[] getFilteredTenantConfigs(TenantConfig[] inputTenantConfig
}

public boolean isConnectionUriDomainPresentInDb(String cud) {
for (TenantConfig config : this.allTenantConfigsFromDbDangerous) {
if (config.tenantIdentifier.getConnectionUriDomain().equals(cud)) {
return true;
}
}

return false;
return this.dangerous_allCUDsFromDb.contains(cud);
}
}

0 comments on commit f9a812d

Please sign in to comment.