Skip to content

Commit

Permalink
[Performance #285] receive long running tasks as a full map
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskabc committed Sep 12, 2024
1 parent d34ef90 commit 001692c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
17 changes: 4 additions & 13 deletions src/reducer/TermItReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ import VocabularyUtils, { IRIImpl } from "../util/VocabularyUtils";
import TermOccurrence from "../model/TermOccurrence";
import { Breadcrumb } from "../model/Breadcrumb";
import AnnotatorLegendFilter from "../model/AnnotatorLegendFilter";
import {
LongRunningTask,
LongRunningTaskState,
} from "../model/LongRunningTask";
import { LongRunningTask } from "../model/LongRunningTask";

function isAsyncSuccess(action: AsyncAction) {
return action.status === AsyncActionStatus.SUCCESS;
Expand Down Expand Up @@ -707,20 +704,14 @@ function accessLevels(
}

function runningTasks(
state: { [key: string]: LongRunningTask } = {},
action: AsyncActionSuccess<LongRunningTask>
state: { [uuid: string]: LongRunningTask } = {},
action: AsyncActionSuccess<{ [uuid: string]: LongRunningTask }>
) {
if (action.type === ActionType.LONG_RUNNING_TASKS_UPDATE) {
if (!action.payload) {
return {};
}
const newState = Object.assign({}, state, {
[action.payload.uuid]: action.payload,
});
if (action.payload.state === LongRunningTaskState.DONE) {
delete newState[action.payload.uuid];
}
return newState;
return Object.assign({}, action.payload);
}
return state;
}
Expand Down
38 changes: 13 additions & 25 deletions src/reducer/WebSocketUtilityDispatchers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { IMessage } from "react-stomp-hooks";
import { Action } from "redux";
import { ThunkDispatch } from "../util/Types";
import {
LongRunningTask,
LongRunningTaskState,
} from "../model/LongRunningTask";
import { isNumber, isString } from "lodash";
import { LongRunningTask } from "../model/LongRunningTask";
import {
asyncActionSuccess,
asyncActionSuccessWithPayload,
Expand All @@ -18,28 +14,20 @@ export function updateLongRunningTasks(message: IMessage, action: Action) {
return;
}

const task: LongRunningTask = JSON.parse(message.body);
const tasks: { [uuid: string]: LongRunningTask } = JSON.parse(message.body);

if (
!(
task &&
task.state &&
isString(task.uuid) &&
isString(task.name) &&
LongRunningTaskState[task.state] &&
(isNumber(task.startedAt) || !task.startedAt)
) ||
task.name.trim() === ""
) {
return;
}

if (task.startedAt) {
task.startedAt = new Date(task.startedAt * 1000);
}
const mapped = Object.keys(tasks).map((uuid) => {
const task = tasks[uuid];
if (task.startedAt) {
// @ts-ignore
task.startedAt = new Date(task.startedAt * 1000);
task.startedAt.setMilliseconds(0); // round to second
}

task.name = "longrunningtasks.name." + task.name;
task.name = "longrunningtasks.name." + task.name;
return task;
});

dispatch(asyncActionSuccessWithPayload(action, task));
dispatch(asyncActionSuccessWithPayload(action, mapped));
};
}

0 comments on commit 001692c

Please sign in to comment.