Page MenuHomePhabricator

D9955.id33736.diff
No OneTemporary

D9955.id33736.diff

diff --git a/web/database/utils/store.js b/web/database/utils/store.js
--- a/web/database/utils/store.js
+++ b/web/database/utils/store.js
@@ -2,7 +2,11 @@
import { reportStoreOpsHandlers } from 'lib/ops/report-store-ops.js';
import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js';
-import type { ClientStore } from 'lib/types/store-ops-types.js';
+import { canUseDatabaseOnWeb } from 'lib/shared/web-database.js';
+import type {
+ ClientStore,
+ StoreOperations,
+} from 'lib/types/store-ops-types.js';
import { workerRequestMessageTypes } from '../../types/worker-types.js';
import { getDatabaseModule } from '../database-module-provider.js';
@@ -46,4 +50,32 @@
return result;
}
-export { getClientStore };
+async function processDBStoreOperations(
+ storeOperations: StoreOperations,
+ userID: ?string,
+): Promise<void> {
+ const { draftStoreOperations, threadStoreOperations, reportStoreOperations } =
+ storeOperations;
+
+ const convertedThreadStoreOperations = canUseDatabaseOnWeb(userID)
+ ? threadStoreOpsHandlers.convertOpsToClientDBOps(threadStoreOperations)
+ : [];
+ const convertedReportStoreOperations =
+ reportStoreOpsHandlers.convertOpsToClientDBOps(reportStoreOperations);
+
+ const databaseModule = await getDatabaseModule();
+ const isSupported = await databaseModule.isDatabaseSupported();
+ if (!isSupported) {
+ return;
+ }
+ await databaseModule.schedule({
+ type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
+ storeOperations: {
+ draftStoreOperations,
+ reportStoreOperations: convertedReportStoreOperations,
+ threadStoreOperations: convertedThreadStoreOperations,
+ },
+ });
+}
+
+export { getClientStore, processDBStoreOperations };
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,8 +7,6 @@
logOutActionTypes,
deleteAccountActionTypes,
} from 'lib/actions/user-actions.js';
-import { reportStoreOpsHandlers } from 'lib/ops/report-store-ops.js';
-import { threadStoreOpsHandlers } from 'lib/ops/thread-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';
@@ -48,11 +46,10 @@
import reduceNavInfo from './nav-reducer.js';
import { onStateDifference } from './redux-debug-utils.js';
import { getVisibility } from './visibility.js';
-import { getDatabaseModule } from '../database/database-module-provider.js';
+import { processDBStoreOperations } from '../database/utils/store.js';
import { activeThreadSelector } from '../selectors/nav-selectors.js';
import { type NavInfo } from '../types/nav-types.js';
import type { InitialReduxState } from '../types/redux-types.js';
-import { workerRequestMessageTypes } from '../types/worker-types.js';
export type WindowDimensions = { width: number, height: number };
@@ -194,43 +191,10 @@
const baseReducerResult = baseReducer(state, action, onStateDifference);
state = baseReducerResult.state;
- const {
- storeOperations: {
- draftStoreOperations,
- reportStoreOperations,
- threadStoreOperations,
- },
- } = baseReducerResult;
- if (
- draftStoreOperations.length > 0 ||
- reportStoreOperations.length > 0 ||
- threadStoreOperations.length > 0
- ) {
- (async () => {
- const databaseModule = await getDatabaseModule();
- const isSupported = await databaseModule.isDatabaseSupported();
- if (!isSupported) {
- return;
- }
- const convertedReportStoreOperations =
- reportStoreOpsHandlers.convertOpsToClientDBOps(reportStoreOperations);
- const convertedThreadStoreOperations = canUseDatabaseOnWeb(
- state.currentUserInfo?.id,
- )
- ? threadStoreOpsHandlers.convertOpsToClientDBOps(
- threadStoreOperations,
- )
- : [];
- await databaseModule.schedule({
- type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
- storeOperations: {
- draftStoreOperations,
- reportStoreOperations: convertedReportStoreOperations,
- threadStoreOperations: convertedThreadStoreOperations,
- },
- });
- })();
- }
+ processDBStoreOperations(
+ baseReducerResult.storeOperations,
+ state.currentUserInfo?.id,
+ );
}
const communityPickerStore = reduceCommunityPickerStore(

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 8, 10:18 PM (19 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2445376
Default Alt Text
D9955.id33736.diff (4 KB)

Event Timeline