From edb401b212c28a07e78f83363a1446e36e2b1b27 Mon Sep 17 00:00:00 2001 From: benjamin <ben@elixxir.io> Date: Wed, 26 Oct 2022 19:57:07 -0700 Subject: [PATCH] undid a db hack --- indexedDb/init.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/indexedDb/init.go b/indexedDb/init.go index 22ea3319..d6d9d673 100644 --- a/indexedDb/init.go +++ b/indexedDb/init.go @@ -93,6 +93,27 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher, return nil, err } + // FIXME: The below is a hack that for some reason prevents moving on with + // uninitialized database despite the previous call to Await. + // It would be idea to find a different solution. + // Close and open again to ensure the state is finalized + err = db.Close() + if err != nil { + return nil, err + } + openRequest, err = idb.Global().Open(ctx, databaseName, currentVersion, + func(db *idb.Database, oldVersion, newVersion uint) error { + return nil + }) + if err != nil { + return nil, err + } + // Wait for database open to finish + db, err = openRequest.Await(ctx) + if err != nil { + return nil, err + } + // Save the encryption status to storage encryptionStatus := encryption != nil loadedEncryptionStatus, err := storage.StoreIndexedDbEncryptionStatus( @@ -111,7 +132,7 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher, // Attempt to ensure the database has been properly initialized wrapper := &wasmModel{db: db, receivedMessageCB: cb, cipher: encryption} - return wrapper, wrapper.hackTestDb() + return wrapper, nil } // v1Upgrade performs the v0 -> v1 database upgrade. -- GitLab