Page MenuHomePhabricator

D7248.id24376.diff
No OneTemporary

D7248.id24376.diff

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
@@ -107,72 +107,68 @@
async function processAppRequest(
message: WorkerRequestMessage,
): Promise<?WorkerResponseMessage> {
+ // non-database operations
if (message.type === workerRequestMessageTypes.PING) {
return {
type: workerResponseMessageTypes.PONG,
text: 'PONG',
};
- } else if (message.type === workerRequestMessageTypes.INIT) {
- await initDatabase(message.sqljsFilePath, message.sqljsFilename);
- return;
} else if (
message.type === workerRequestMessageTypes.GENERATE_DATABASE_ENCRYPTION_KEY
) {
const cryptoKey = await generateDatabaseCryptoKey();
await localforage.setItem(SQLITE_ENCRYPTION_KEY, cryptoKey);
return;
- } else if (
- message.type === workerRequestMessageTypes.PROCESS_STORE_OPERATIONS
- ) {
- const { draftStoreOperations } = message.storeOperations;
- if (draftStoreOperations) {
- processDraftStoreOperations(draftStoreOperations);
- }
+ }
+
+ // database operations
+ if (message.type === workerRequestMessageTypes.INIT) {
+ await initDatabase(message.sqljsFilePath, message.sqljsFilename);
return;
- } else if (message.type === workerRequestMessageTypes.GET_CLIENT_STORE) {
+ }
+
+ if (!sqliteDb) {
+ throw new Error('Database not initialized');
+ }
+
+ // read-only operations
+ if (message.type === workerRequestMessageTypes.GET_CLIENT_STORE) {
return {
type: workerResponseMessageTypes.CLIENT_STORE,
store: getClientStore(),
};
- } else if (message.type === workerRequestMessageTypes.SET_CURRENT_USER_ID) {
- if (!sqliteDb) {
- throw new Error('Database not initialized');
- }
- setMetadata(sqliteDb, CURRENT_USER_ID_KEY, message.userID);
- return;
} else if (message.type === workerRequestMessageTypes.GET_CURRENT_USER_ID) {
- if (!sqliteDb) {
- throw new Error('Database not initialized');
- }
- const userID = getMetadata(sqliteDb, CURRENT_USER_ID_KEY);
return {
type: workerResponseMessageTypes.GET_CURRENT_USER_ID,
- userID,
+ userID: getMetadata(sqliteDb, CURRENT_USER_ID_KEY),
};
} else if (
message.type === workerRequestMessageTypes.GET_PERSIST_STORAGE_ITEM
) {
- if (!sqliteDb) {
- throw new Error('Database not initialized');
- }
return {
type: workerResponseMessageTypes.GET_PERSIST_STORAGE_ITEM,
item: getPersistStorageItem(sqliteDb, message.key),
};
+ }
+
+ // write operations
+ if (message.type === workerRequestMessageTypes.PROCESS_STORE_OPERATIONS) {
+ const { draftStoreOperations } = message.storeOperations;
+ if (draftStoreOperations) {
+ processDraftStoreOperations(draftStoreOperations);
+ }
+ return;
+ } else if (message.type === workerRequestMessageTypes.SET_CURRENT_USER_ID) {
+ setMetadata(sqliteDb, CURRENT_USER_ID_KEY, message.userID);
+ return;
} else if (
message.type === workerRequestMessageTypes.SET_PERSIST_STORAGE_ITEM
) {
- if (!sqliteDb) {
- throw new Error('Database not initialized');
- }
setPersistStorageItem(sqliteDb, message.key, message.item);
return;
} else if (
message.type === workerRequestMessageTypes.REMOVE_PERSIST_STORAGE_ITEM
) {
- if (!sqliteDb) {
- throw new Error('Database not initialized');
- }
removePersistStorageItem(sqliteDb, message.key);
return;
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 5:55 AM (20 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574199
Default Alt Text
D7248.id24376.diff (3 KB)

Event Timeline