Page MenuHomePhabricator

D8547.diff
No OneTemporary

D8547.diff

diff --git a/web/database/db-module.js b/web/database/db-module.js
new file mode 100644
--- /dev/null
+++ b/web/database/db-module.js
@@ -0,0 +1,25 @@
+// @flow
+
+import Module from './_generated/comm-query-executor.js';
+import type { EmscriptenModule } from './types/module.js';
+import { DEFAULT_COMM_QUERY_EXECUTOR_FILENAME } from './utils/constants.js';
+
+function getDatabaseModule(
+ databaseModuleFilename?: ?string,
+ databaseModuleFilePath?: string,
+): EmscriptenModule {
+ const fileName = databaseModuleFilename
+ ? databaseModuleFilename
+ : DEFAULT_COMM_QUERY_EXECUTOR_FILENAME;
+
+ return Module({
+ locateFile: (path: string, prefix?: string) => {
+ if (databaseModuleFilePath) {
+ return `${databaseModuleFilePath}/${fileName}`;
+ }
+ return `${prefix ?? ''}${fileName}`;
+ },
+ });
+}
+
+export { getDatabaseModule };
diff --git a/web/database/utils/constants.js b/web/database/utils/constants.js
--- a/web/database/utils/constants.js
+++ b/web/database/utils/constants.js
@@ -10,6 +10,8 @@
export const DATABASE_WORKER_PATH = '/worker/database';
export const SQLJS_FILE_PATH = '/compiled/webworkers';
+export const DEFAULT_COMM_QUERY_EXECUTOR_FILENAME = 'comm_query_executor.wasm';
+
export const DB_SUPPORTED_OS: $ReadOnlyArray<string> = [
'Windows 10',
'Linux',
diff --git a/web/database/worker/db-worker.js b/web/database/worker/db-worker.js
--- a/web/database/worker/db-worker.js
+++ b/web/database/worker/db-worker.js
@@ -19,7 +19,7 @@
type WorkerRequestProxyMessage,
workerWriteRequests,
} from '../../types/worker-types.js';
-import Module from '../_generated/comm-query-executor.js';
+import { getDatabaseModule } from '../db-module.js';
import { migrate, setupSQLiteDB } from '../queries/db-queries.js';
import {
getAllDrafts,
@@ -60,22 +60,13 @@
let persistNeeded: boolean = false;
let persistInProgress: boolean = false;
-const defaultCommQueryExecutorFilename = 'comm_query_executor.wasm';
-
async function initDatabase(
sqljsFilePath: string,
sqljsFilename: ?string,
commQueryExecutorFilename: ?string,
encryptionKeyJWK?: ?SubtleCrypto$JsonWebKey,
) {
- const dbModule = Module({
- locateFile: function () {
- if (commQueryExecutorFilename) {
- return `${sqljsFilePath}/${commQueryExecutorFilename}`;
- }
- return `${sqljsFilePath}/${defaultCommQueryExecutorFilename}`;
- },
- });
+ const dbModule = getDatabaseModule(commQueryExecutorFilename, sqljsFilePath);
try {
const result = dbModule.CommQueryExecutor.testDBOperation();

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 8, 9:32 PM (21 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2446089
Default Alt Text
D8547.diff (2 KB)

Event Timeline