We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c5a77e8 commit 1aa3108Copy full SHA for 1aa3108
1 file changed
src/OceanNode.ts
@@ -343,12 +343,19 @@ export class OceanNode {
343
return this.config.hasP2P || false
344
}
345
346
+ private dbInitPromise: Promise<Database> | null = null
347
async getDatabase(forceReload: boolean = false): Promise<Database> {
348
if (!this.database || forceReload) {
- const { dbConfig } = this.config
349
- if (dbConfig && dbConfig.url) {
350
- this.database = await Database.init(dbConfig)
+ if (!this.dbInitPromise || forceReload) {
+ const { dbConfig } = this.config
351
+ if (dbConfig && dbConfig.url) {
352
+ this.dbInitPromise = Database.init(dbConfig).then((db) => {
353
+ this.database = db
354
+ return db
355
+ })
356
+ }
357
358
+ return await this.dbInitPromise
359
360
return this.database
361
0 commit comments