Skip to content

Commit

Permalink
simplify collab/sync (#5848)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwdchang authored Jan 2, 2025
1 parent 81e3903 commit ef84365
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ import { useRouter, useRoute } from 'vue-router';
import { MenuItem } from 'primevue/menuitem';
import * as EventService from '@/services/event';
import { useProjects } from '@/composables/project';
import useAuthStore from '@/stores/auth';
// import useAuthStore from '@/stores/auth';
import { cloneNoteBookSession } from '@/services/notebook-session';
import * as SimulateCiemssOp from '@/components/workflow/ops/simulate-ciemss/mod';
import * as StratifyMiraOp from '@/components/workflow/ops/stratify-mira/mod';
Expand All @@ -212,7 +212,7 @@ import { activeProjectId } from '@/composables/activeProject';
const WORKFLOW_SAVE_INTERVAL = 4000;
const currentUserId = useAuthStore().user?.id;
// const currentUserId = useAuthStore().user?.id;
const registry = new workflowService.WorkflowRegistry();
registry.registerOp(SimulateCiemssOp);
Expand Down Expand Up @@ -289,13 +289,11 @@ const _updateWorkflow = (event: ClientEvent<any>) => {
if (event.data.id !== wf.value.getId()) {
return;
}
const delayUpdate = isDragging || event.userId === currentUserId;
wf.value.update(event.data as Workflow, delayUpdate);
wf.value.update(event.data as Workflow);
};
const saveWorkflowDebounced = debounce(_saveWorkflow, 400);
const updateWorkflowHandler = debounce(_updateWorkflow, 250);
const saveWorkflowDebounced = debounce(_saveWorkflow, 1000);
const updateWorkflowHandler = debounce(_updateWorkflow, 800);
const saveWorkflowHandler = () => {
saveWorkflowDebounced();
Expand Down
50 changes: 22 additions & 28 deletions packages/client/hmi-client/src/services/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,8 @@ export class WorkflowWrapper {
* FIXME: Need to split workflow into different categories and sending the commands
* instead of the result. It is possible here to become de-synced: eg state-update-response
* comes in as we are about to change the output ports.
*
* delayUpdate is a used to indicate there are actions in progress, and an update from
* the DB can potentially overwrite what the user had already done that have yet to be flushed
* to the backend. In situation like this, we will update the version (so our subsequent updates are
* not rejected) and skip the rest. For example, the user may be dragging an operator on the
* canvas when the db upate comes in.
* */
update(updatedWF: Workflow, delayUpdate: boolean) {
update(updatedWF: Workflow) {
if (updatedWF.id !== this.wf.id) {
throw new Error(`Workflow failed, inconsistent ids updated=${updatedWF.id} self=${this.wf.id}`);
}
Expand All @@ -74,27 +68,27 @@ export class WorkflowWrapper {
const updatedNodeMap = new Map<string, WorkflowNode<any>>(updatedWF.nodes.map((n) => [n.id, n]));
const updatedEdgeMap = new Map<string, WorkflowEdge>(updatedWF.edges.map((e) => [e.id, e]));

if (delayUpdate) {
for (let i = 0; i < nodes.length; i++) {
const nodeId = nodes[i].id;
const updated = updatedNodeMap.get(nodeId);
if (updated) {
if (!nodes[i].version || (updated.version as number) > (nodes[i].version as number)) {
nodes[i].version = updated.version;
}
}
}
for (let i = 0; i < edges.length; i++) {
const edgeId = edges[i].id;
const updated = updatedEdgeMap.get(edgeId);
if (updated) {
if (!edges[i].version || (updated.version as number) > (edges[i].version as number)) {
edges[i].version = updated.version;
}
}
}
return;
}
/* FIXME: Comment out to to simplify sync logic, to remove if things are stable - Jan 2025 */
// if (delayUpdate) {
// for (let i = 0; i < nodes.length; i++) {
// const nodeId = nodes[i].id;
// const updated = updatedNodeMap.get(nodeId);
// if (updated) {
// if (!nodes[i].version || (updated.version as number) > (nodes[i].version as number)) {
// nodes[i].version = updated.version;
// }
// }
// }
// for (let i = 0; i < edges.length; i++) {
// const edgeId = edges[i].id;
// const updated = updatedEdgeMap.get(edgeId);
// if (updated) {
// if (!edges[i].version || (updated.version as number) > (edges[i].version as number)) {
// edges[i].version = updated.version;
// }
// }
// } return;
// }

// Update and deletes
for (let i = 0; i < nodes.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public Optional<Workflow> updateAsset(
final UUID projectId,
final Schema.Permission hasWritePermission
) throws IOException, IllegalArgumentException {
final long updateStart = System.currentTimeMillis();
// Fetch database copy, we will update into it
final Workflow dbWorkflow = getAsset(asset.getId(), hasWritePermission).get();

Expand Down Expand Up @@ -191,14 +190,7 @@ public Optional<Workflow> updateAsset(
dbWorkflowEdges.add(pair.getValue());
}

final long resolveEnd = System.currentTimeMillis();
log.info("Resolve workflow " + dbWorkflow.getId() + " took " + (resolveEnd - updateStart));

final Optional<Workflow> result = super.updateAsset(dbWorkflow, projectId, hasWritePermission);

final long updateEnd = System.currentTimeMillis();
log.info("Update workflow to DB " + dbWorkflow.getId() + " took " + (updateEnd - resolveEnd));

return result;
}

Expand Down

0 comments on commit ef84365

Please sign in to comment.