HomePhabricator
Diffusion Comm be85d5c7b530

[sqlite] implement processing community store ops on worker

Description

[sqlite] implement processing community store ops on worker

Summary:
introduce community store + community store ops logic to web worker

Linear task: https://linear.app/comm/issue/ENG-6534/implement-processing-community-store-ops

Depends on D11153

Test Plan:
Ran the following code + confirmed things worked as expected

  const TEST_COMMUNITY_1: CommunityInfo = {
    enabledApps: {
      calendar: false,
      wiki: false,
      tasks: true,
      files: true,
    },
  };

  const TEST_COMMUNITY_2: CommunityInfo = {
    enabledApps: {
      calendar: true,
      wiki: false,
      tasks: false,
      files: false,
    },
  };

  const databaseModule = await getDatabaseModule();

  let data = await databaseModule.schedule({
    type: workerRequestMessageTypes.GET_CLIENT_STORE,
  });
  console.log(data.store.communites);

  await databaseModule.schedule({
    type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
    storeOperations: {
      communityStoreOperations: [
        {
          type: 'replace_community',
          payload: {
            id: '1',
            communityInfo: TEST_COMMUNITY_1,
          },
        },
        {
          type: 'replace_community',
          payload: {
            id: '2',
            communityInfo: TEST_COMMUNITY_2,
          },
        },
      ],
    },
  });

  data = await databaseModule.schedule({
    type: workerRequestMessageTypes.GET_CLIENT_STORE,
  });
  console.log(data.store.communites);

  const community2Updated: CommunityInfo = {
    enabledApps: {
      calendar: true,
      wiki: true,
      tasks: true,
      files: true,
    },
  };

  await databaseModule.schedule({
    type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
    storeOperations: {
      communityStoreOperations: [
        {
          type: 'replace_community',
          payload: {
            id: '2',
            communityInfo: community2Updated,
          },
        },
      ],
    },
  });

  data = await databaseModule.schedule({
    type: workerRequestMessageTypes.GET_CLIENT_STORE,
  });
  console.log(data.store.communites);

  await databaseModule.schedule({
    type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
    storeOperations: {
      communityStoreOperations: [
        {
          type: 'remove_communites',
          payload: {
            ids: ['1'],
          },
        },
      ],
    },
  });

  data = await databaseModule.schedule({
    type: workerRequestMessageTypes.GET_CLIENT_STORE,
  });
  console.log(data.store.communities);

await databaseModule.schedule({
  type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
  storeOperations: {
    communityStoreOperations: [
      {
        type: 'remove_all_communities',
      },
    ],
  },
});

data = await databaseModule.schedule({
  type: workerRequestMessageTypes.GET_CLIENT_STORE,
});
console.log(data.store.communites);

Reviewers: atul, inka, kamil

Reviewed By: kamil

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D11164

Details

Provenance
ginsuAuthored on Feb 20 2024, 1:26 PM
Reviewer
kamil
Differential Revision
D11164: [sqlite] implement processing community store ops on worker
Parents
rCOMMb1f35f4bd8e6: [sqlite] implement c++ code to get communities
Branches
Unknown
Tags
Unknown