@@ -54,6 +54,7 @@ public class StorageLayer extends ResourceDistributor.SingletonResource {
5454 public static final String RESOURCE_KEY = "io.supertokens.storageLayer.StorageLayer" ;
5555 private final Storage storage ;
5656 private static URLClassLoader ucl = null ;
57+ private static Storage storageInstanceForEnv = null ;
5758
5859 public Storage getUnderlyingStorage () {
5960 return storage ;
@@ -68,30 +69,34 @@ public static Storage getNewBulkImportProxyStorageInstance(Main main, JsonObject
6869 }
6970
7071 public static void updateConfigJsonFromEnv (Main main , JsonObject configJson ) {
71- Storage result ;
72- if (StorageLayer .ucl == null ) {
73- result = new Start (main );
74- } else {
75- Storage storageLayer = null ;
76- ServiceLoader <Storage > sl = ServiceLoader .load (Storage .class , ucl );
77- for (Storage plugin : sl ) {
78- if (storageLayer == null ) {
79- storageLayer = plugin ;
72+ if (storageInstanceForEnv == null ) {
73+ Storage result ;
74+ if (StorageLayer .ucl == null ) {
75+ result = new Start (main );
76+ } else {
77+ Storage storageLayer = null ;
78+ ServiceLoader <Storage > sl = ServiceLoader .load (Storage .class , ucl );
79+ for (Storage plugin : sl ) {
80+ if (storageLayer == null ) {
81+ storageLayer = plugin ;
82+ } else {
83+ throw new QuitProgramException (
84+ "Multiple database plugins found. Please make sure that just one plugin is in the "
85+ + "/plugin" + " "
86+ + "folder of the installation. Alternatively, please redownload and install "
87+ + "SuperTokens" + "." );
88+ }
89+ }
90+ if (storageLayer != null ) {
91+ result = storageLayer ;
8092 } else {
81- throw new QuitProgramException (
82- "Multiple database plugins found. Please make sure that just one plugin is in the "
83- + "/plugin" + " "
84- + "folder of the installation. Alternatively, please redownload and install "
85- + "SuperTokens" + "." );
93+ result = new Start (main );
8694 }
8795 }
88- if (storageLayer != null ) {
89- result = storageLayer ;
90- } else {
91- result = new Start (main );
92- }
96+ storageInstanceForEnv = result ;
9397 }
94- result .updateConfigJsonFromEnv (configJson );
98+
99+ storageInstanceForEnv .updateConfigJsonFromEnv (configJson );
95100 }
96101
97102 private static Storage getNewInstance (Main main , JsonObject config , TenantIdentifier tenantIdentifier , boolean doNotLog , boolean isBulkImportProxy ) throws InvalidConfigException {
0 commit comments