diff --git a/web/shared-worker/utils/constants.js b/web/shared-worker/utils/constants.js --- a/web/shared-worker/utils/constants.js +++ b/web/shared-worker/utils/constants.js @@ -3,6 +3,7 @@ import localforage from 'localforage'; export const SQLITE_CONTENT = 'sqliteFileContent'; +export const RESTORED_SQLITE_CONTENT = 'restoredSQLiteContent'; export const SQLITE_ENCRYPTION_KEY = 'encryptionKey'; export const SQLITE_STAMPED_USER_ID_KEY = 'current_user_id'; diff --git a/web/shared-worker/worker/shared-worker.js b/web/shared-worker/worker/shared-worker.js --- a/web/shared-worker/worker/shared-worker.js +++ b/web/shared-worker/worker/shared-worker.js @@ -49,6 +49,7 @@ SQLITE_ENCRYPTION_KEY, DEFAULT_BACKUP_CLIENT_FILENAME, SQLITE_RESTORE_DATABASE_PATH, + RESTORED_SQLITE_CONTENT, } from '../utils/constants.js'; import { clearSensitiveData, @@ -135,7 +136,12 @@ async function persist() { persistInProgress = true; const sqliteQueryExecutor = getSQLiteQueryExecutor(); + const restoredQueryExecutor = getSQLiteQueryExecutor( + databaseIdentifier.RESTORED, + ); const dbModule = getDBModule(); + // restoredQueryExecutor does not need to be defined, as it is needed + // only when restoring if (!sqliteQueryExecutor || !dbModule) { persistInProgress = false; throw new Error( @@ -155,7 +161,21 @@ throw new Error('Encryption key is missing'); } const encryptedData = await encryptData(dbData, encryptionKey); - await localforage.setItem(SQLITE_CONTENT, encryptedData); + + const promises: Array> = []; + promises.push(localforage.setItem(SQLITE_CONTENT, encryptedData)); + + if (restoredQueryExecutor) { + const restoredDBData = exportDatabaseContent( + dbModule, + SQLITE_RESTORE_DATABASE_PATH, + ); + promises.push( + localforage.setItem(RESTORED_SQLITE_CONTENT, restoredDBData), + ); + } + + await Promise.all(promises); } persistInProgress = false; }