Page MenuHomePhabricator

D11324.diff
No OneTemporary

D11324.diff

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
@@ -7,6 +7,12 @@
getClientStoreFromQueryExecutor,
processDBStoreOperations,
} from './process-operations.js';
+import {
+ getDBModule,
+ getSQLiteQueryExecutor,
+ setDBModule,
+ setSQLiteQueryExecutor,
+} from './worker-database.js';
import initBackupClientModule from '../../backup-client-wasm/wasm/backup-client-wasm.js';
import {
decryptData,
@@ -25,8 +31,6 @@
workerWriteRequests,
} from '../../types/worker-types.js';
import { getDatabaseModule } from '../db-module.js';
-import { type EmscriptenModule } from '../types/module.js';
-import { type SQLiteQueryExecutor } from '../types/sqlite-query-executor.js';
import {
COMM_SQLITE_DATABASE_PATH,
CURRENT_USER_ID_KEY,
@@ -45,9 +49,6 @@
let encryptionKey: ?CryptoKey = null;
-let sqliteQueryExecutor: ?SQLiteQueryExecutor = null;
-let dbModule: ?EmscriptenModule = null;
-
let persistNeeded: boolean = false;
let persistInProgress: boolean = false;
@@ -56,6 +57,8 @@
commQueryExecutorFilename: ?string,
encryptionKeyJWK?: ?SubtleCrypto$JsonWebKey,
) {
+ const dbModule = getDBModule();
+ const sqliteQueryExecutor = getSQLiteQueryExecutor();
if (!!dbModule && !!sqliteQueryExecutor) {
console.log('Database already initialized');
return;
@@ -65,7 +68,7 @@
? dbModule
: getDatabaseModule(commQueryExecutorFilename, webworkerModulesFilePath);
if (!dbModule) {
- dbModule = newModule;
+ setDBModule(newModule);
}
if (encryptionKeyJWK) {
@@ -100,8 +103,8 @@
} else {
console.info('Creating fresh database');
}
- sqliteQueryExecutor = new newModule.SQLiteQueryExecutor(
- COMM_SQLITE_DATABASE_PATH,
+ setSQLiteQueryExecutor(
+ new newModule.SQLiteQueryExecutor(COMM_SQLITE_DATABASE_PATH),
);
}
@@ -120,8 +123,9 @@
async function persist() {
persistInProgress = true;
- const module = dbModule;
- if (!sqliteQueryExecutor || !module) {
+ const sqliteQueryExecutor = getSQLiteQueryExecutor();
+ const dbModule = getDBModule();
+ if (!sqliteQueryExecutor || !dbModule) {
persistInProgress = false;
throw new Error(
'Database not initialized while persisting database content',
@@ -134,7 +138,7 @@
while (persistNeeded) {
persistNeeded = false;
- const dbData = exportDatabaseContent(module, COMM_SQLITE_DATABASE_PATH);
+ const dbData = exportDatabaseContent(dbModule, COMM_SQLITE_DATABASE_PATH);
if (!encryptionKey) {
persistInProgress = false;
throw new Error('Encryption key is missing');
@@ -162,6 +166,9 @@
return undefined;
}
+ const sqliteQueryExecutor = getSQLiteQueryExecutor();
+ const dbModule = getDBModule();
+
// database operations
if (message.type === workerRequestMessageTypes.INIT) {
const promises = [
@@ -191,7 +198,7 @@
sqliteQueryExecutor,
);
}
- sqliteQueryExecutor = null;
+ setSQLiteQueryExecutor(null);
return undefined;
}
diff --git a/web/shared-worker/worker/worker-database.js b/web/shared-worker/worker/worker-database.js
new file mode 100644
--- /dev/null
+++ b/web/shared-worker/worker/worker-database.js
@@ -0,0 +1,31 @@
+// @flow
+
+import type { EmscriptenModule } from '../types/module.js';
+import type { SQLiteQueryExecutor } from '../types/sqlite-query-executor.js';
+
+let sqliteQueryExecutor: ?SQLiteQueryExecutor = null;
+
+function getSQLiteQueryExecutor(): ?SQLiteQueryExecutor {
+ return sqliteQueryExecutor;
+}
+
+function setSQLiteQueryExecutor(newSQLiteQueryExecutor: ?SQLiteQueryExecutor) {
+ sqliteQueryExecutor = newSQLiteQueryExecutor;
+}
+
+let dbModule: ?EmscriptenModule = null;
+
+function getDBModule(): ?EmscriptenModule {
+ return dbModule;
+}
+
+function setDBModule(newDBModule: EmscriptenModule) {
+ dbModule = newDBModule;
+}
+
+export {
+ getSQLiteQueryExecutor,
+ setSQLiteQueryExecutor,
+ getDBModule,
+ setDBModule,
+};

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 1:27 AM (22 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2581887
Default Alt Text
D11324.diff (3 KB)

Event Timeline