Page MenuHomePhabricator

D7985.id27313.diff
No OneTemporary

D7985.id27313.diff

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
@@ -19,6 +19,7 @@
import type {
ReportStoreOperation,
ClientDBReport,
+ ClientDBReportStoreOperation,
} from '../ops/report-store-ops.js';
export type StoreOperations = {
@@ -32,6 +33,7 @@
+draftStoreOperations?: $ReadOnlyArray<ClientDBDraftStoreOperation>,
+threadStoreOperations?: $ReadOnlyArray<ClientDBThreadStoreOperation>,
+messageStoreOperations?: $ReadOnlyArray<ClientDBMessageStoreOperation>,
+ +reportStoreOperations?: $ReadOnlyArray<ClientDBReportStoreOperation>,
};
export type ClientDBStore = {
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,7 @@
import localforage from 'localforage';
import initSqlJs, { type SqliteDatabase } from 'sql.js';
+import type { ClientDBReportStoreOperation } from 'lib/ops/report-store-ops.js';
import type {
ClientDBDraftStoreOperation,
DraftStoreOperation,
@@ -26,6 +27,11 @@
updateDraft,
} from '../queries/draft-queries.js';
import { getMetadata, setMetadata } from '../queries/metadata-queries.js';
+import {
+ removeAllReports,
+ removeReports,
+ updateReport,
+} from '../queries/report-queries.js';
import {
getPersistStorageItem,
removePersistStorageItem,
@@ -120,6 +126,27 @@
}
}
+function processReportStoreOperations(
+ operations: $ReadOnlyArray<ClientDBReportStoreOperation>,
+) {
+ if (!sqliteDb) {
+ throw new Error('Database not initialized');
+ }
+ for (const operation: ClientDBReportStoreOperation of operations) {
+ if (operation.type === 'remove_all_reports') {
+ removeAllReports(sqliteDb);
+ } else if (operation.type === 'remove_reports') {
+ const { ids } = operation.payload;
+ removeReports(sqliteDb, ids);
+ } else if (operation.type === 'replace_report') {
+ const { id, report } = operation.payload;
+ updateReport(sqliteDb, id, report);
+ } else {
+ throw new Error('Unsupported report operation');
+ }
+ }
+}
+
function getClientStore(): ClientDBStore {
if (!sqliteDb) {
throw new Error('Database not initialized');
@@ -217,10 +244,14 @@
}
if (message.type === workerRequestMessageTypes.PROCESS_STORE_OPERATIONS) {
- const { draftStoreOperations } = message.storeOperations;
+ const { draftStoreOperations, reportStoreOperations } =
+ message.storeOperations;
if (draftStoreOperations) {
processDraftStoreOperations(draftStoreOperations);
}
+ if (reportStoreOperations) {
+ processReportStoreOperations(reportStoreOperations);
+ }
} else if (message.type === workerRequestMessageTypes.SET_CURRENT_USER_ID) {
setMetadata(sqliteDb, CURRENT_USER_ID_KEY, message.userID);
} else if (
diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js
--- a/web/redux/redux-setup.js
+++ b/web/redux/redux-setup.js
@@ -7,6 +7,7 @@
logOutActionTypes,
deleteAccountActionTypes,
} from 'lib/actions/user-actions.js';
+import { convertReportStoreOperationToClientDBReportStoreOperation } from 'lib/ops/report-store-ops.js';
import baseReducer from 'lib/reducers/master-reducer.js';
import { mostRecentlyReadThreadSelector } from 'lib/selectors/thread-selectors.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
@@ -176,17 +177,24 @@
state = baseReducerResult.state;
const {
- storeOperations: { draftStoreOperations },
+ storeOperations: { draftStoreOperations, reportStoreOperations },
} = baseReducerResult;
- if (draftStoreOperations.length) {
+ if (draftStoreOperations.length > 0 || reportStoreOperations.length > 0) {
(async () => {
const isSupported = await databaseModule.isDatabaseSupported();
if (!isSupported) {
return;
}
+ const convertedReportStoreOperations =
+ convertReportStoreOperationToClientDBReportStoreOperation(
+ reportStoreOperations,
+ );
await databaseModule.schedule({
type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
- storeOperations: { draftStoreOperations },
+ storeOperations: {
+ draftStoreOperations,
+ reportStoreOperations: convertedReportStoreOperations,
+ },
});
})();
}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 8:36 AM (18 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2693187
Default Alt Text
D7985.id27313.diff (4 KB)

Event Timeline