Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3384068
D11324.id38133.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11324.id38133.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 7:13 PM (21 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597874
Default Alt Text
D11324.id38133.diff (3 KB)
Attached To
Mode
D11324: [web] Move worker database globals to worker-database.js
Attached
Detach File
Event Timeline
Log In to Comment