Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3391268
D7153.id24024.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D7153.id24024.diff
View Options
diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js
--- a/lib/types/store-ops-types.js
+++ b/lib/types/store-ops-types.js
@@ -1,11 +1,26 @@
// @flow
-import type { DraftStoreOperation } from './draft-types.js';
-import type { MessageStoreOperation } from './message-types.js';
-import type { ThreadStoreOperation } from './thread-types.js';
+import type {
+ DraftStoreOperation,
+ ClientDBDraftStoreOperation,
+} from './draft-types.js';
+import type {
+ ClientDBMessageStoreOperation,
+ MessageStoreOperation,
+} from './message-types.js';
+import type {
+ ClientDBThreadStoreOperation,
+ ThreadStoreOperation,
+} from './thread-types.js';
export type StoreOperations = {
+draftStoreOperations: $ReadOnlyArray<DraftStoreOperation>,
+threadStoreOperations: $ReadOnlyArray<ThreadStoreOperation>,
+messageStoreOperations: $ReadOnlyArray<MessageStoreOperation>,
};
+
+export type ClientDBStoreOperations = {
+ +draftStoreOperations?: $ReadOnlyArray<ClientDBDraftStoreOperation>,
+ +threadStoreOperations?: $ReadOnlyArray<ClientDBThreadStoreOperation>,
+ +messageStoreOperations?: $ReadOnlyArray<ClientDBMessageStoreOperation>,
+};
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
@@ -3,6 +3,11 @@
import localforage from 'localforage';
import initSqlJs, { type SqliteDatabase } from 'sql.js';
+import type {
+ ClientDBDraftStoreOperation,
+ DraftStoreOperation,
+} from 'lib/types/draft-types.js';
+
import {
type SharedWorkerMessageEvent,
type WorkerRequestMessage,
@@ -12,6 +17,11 @@
type WorkerRequestProxyMessage,
} from '../../types/worker-types.js';
import { getSQLiteDBVersion, setupSQLiteDB } from '../queries/db-queries.js';
+import {
+ moveDraft,
+ removeAllDrafts,
+ updateDraft,
+} from '../queries/draft-queries.js';
import { SQLITE_CONTENT, SQLITE_ENCRYPTION_KEY } from '../utils/constants.js';
import { generateDatabaseCryptoKey } from '../utils/worker-crypto-utils.js';
@@ -50,6 +60,27 @@
console.info(`Db version: ${dbVersion}`);
}
+function processDraftStoreOperations(
+ operations: $ReadOnlyArray<ClientDBDraftStoreOperation>,
+) {
+ if (!sqliteDb) {
+ throw new Error('Database not initialized');
+ }
+ for (const operation: DraftStoreOperation of operations) {
+ if (operation.type === 'remove_all') {
+ removeAllDrafts(sqliteDb);
+ } else if (operation.type === 'update') {
+ const { key, text } = operation.payload;
+ updateDraft(sqliteDb, key, text);
+ } else if (operation.type === 'move') {
+ const { oldKey, newKey } = operation.payload;
+ moveDraft(sqliteDb, oldKey, newKey);
+ } else {
+ throw new Error('Unsupported draft operation');
+ }
+ }
+}
+
async function processAppRequest(
message: WorkerRequestMessage,
): Promise<?WorkerResponseMessage> {
@@ -67,6 +98,14 @@
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);
+ }
+ return;
}
throw new Error('Request type not supported');
diff --git a/web/types/worker-types.js b/web/types/worker-types.js
--- a/web/types/worker-types.js
+++ b/web/types/worker-types.js
@@ -1,10 +1,13 @@
// @flow
+import type { ClientDBStoreOperations } from 'lib/types/store-ops-types.js';
+
// The types of messages sent from app to worker
export const workerRequestMessageTypes = Object.freeze({
PING: 0,
INIT: 1,
GENERATE_DATABASE_ENCRYPTION_KEY: 2,
+ PROCESS_STORE_OPERATIONS: 3,
});
export type PingWorkerRequestMessage = {
@@ -22,10 +25,16 @@
+type: 2,
};
+export type ProcessStoreOperationsRequestMessage = {
+ +type: 3,
+ +storeOperations: ClientDBStoreOperations,
+};
+
export type WorkerRequestMessage =
| PingWorkerRequestMessage
| InitWorkerRequestMessage
- | GenerateDatabaseEncryptionKeyRequestMessage;
+ | GenerateDatabaseEncryptionKeyRequestMessage
+ | ProcessStoreOperationsRequestMessage;
export type WorkerRequestProxyMessage = {
+id: number,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 3:04 AM (18 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2603453
Default Alt Text
D7153.id24024.diff (4 KB)
Attached To
Mode
D7153: [web-db] process Draft Store Operations on worker
Attached
Detach File
Event Timeline
Log In to Comment