Skip to content

Commit bd086d3

Browse files
committed
When a user submits a user task the update to the tasks state might be delayed because the newest data is not instantly returned due to caching
1 parent d0360df commit bd086d3

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

src/management-system-v2/app/(dashboard)/[environmentId]/tasklist/tasklist.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const Tasklist: React.FC<TasklistProps> = ({ userId, pollingInterval }) => {
5757

5858
const space = useEnvironment();
5959

60-
const { userTasks } = useUserTasks(space, pollingInterval, {
60+
const { userTasks, refetch } = useUserTasks(space, pollingInterval, {
6161
hideNonOwnableTasks: true,
6262
hideUnassignedTasks: false,
6363
});
@@ -291,7 +291,7 @@ const Tasklist: React.FC<TasklistProps> = ({ userId, pollingInterval }) => {
291291
)}
292292
</div>
293293
{(selectedUserTaskID ?? breakpoint.xl) && (
294-
<UserTaskView userId={userId} task={selectedUserTask} />
294+
<UserTaskView userId={userId} task={selectedUserTask} refetch={refetch} />
295295
)}
296296
</div>
297297
);

src/management-system-v2/app/(dashboard)/[environmentId]/tasklist/user-task-view.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ export const UserTaskForm: React.FC<UserTaskFormProps> = ({
9898
type TaskListUserTaskFormProps = {
9999
userId: string;
100100
task?: ExtendedTaskListEntry;
101+
refetch?: () => {};
101102
};
102103

103-
const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userId }) => {
104+
const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userId, refetch }) => {
104105
const space = useEnvironment();
105106

106107
const { message } = App.useApp();
@@ -148,7 +149,9 @@ const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userI
148149
const updatedOwners = await addOwnerToTaskListEntry(space.spaceId, task.id, userId);
149150
if ('error' in updatedOwners) return updatedOwners;
150151
}
151-
return await completeTasklistEntry(space.spaceId, task.id, variables);
152+
const res = await completeTasklistEntry(space.spaceId, task.id, variables, true);
153+
refetch?.();
154+
return res;
152155
},
153156
});
154157
}}

src/management-system-v2/lib/tasks/server-actions.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { getProcessBPMN, getProcessHtmlFormHTML } from '../data/processes';
3434
import { saveInstanceArtifact } from '../data/file-manager-facade';
3535
import { getDBInstance } from '@/lib/data/instance';
3636
import Ability from '../ability/abilityHelper';
37-
import { revalidateTag } from 'next/cache';
37+
import { revalidateTag, updateTag } from 'next/cache';
3838

3939
export async function getGlobalVariablesForHTML(
4040
spaceId: string,
@@ -255,6 +255,9 @@ export async function completeTasklistEntry(
255255
spaceId: string,
256256
userTaskId: string,
257257
variables: { [key: string]: any },
258+
// defines if the request was made in the context of a browser session
259+
// this allows us to use "updateTag" to instantly invalidate the cached instance data
260+
isBrowserRequest = false,
258261
) {
259262
try {
260263
const storedUserTask = await getUserTaskById(userTaskId);
@@ -292,11 +295,24 @@ export async function completeTasklistEntry(
292295
await completeTasklistEntryOnMachine(engine, instanceId, taskId, variables);
293296
}
294297

295-
await updateUserTask(spaceId, userTaskId, {
296-
variableChanges: { ...variableChanges, ...variables },
297-
state: 'COMPLETED',
298-
endTime: !storedUserTask.instanceID ? new Date() : undefined,
298+
await db.userTask.update({
299+
where: {
300+
id: userTaskId,
301+
},
302+
data: {
303+
variableChanges: { ...variableChanges, ...variables },
304+
state: 'COMPLETED',
305+
endTime: !storedUserTask.instanceID ? new Date() : undefined,
306+
},
299307
});
308+
309+
if (isBrowserRequest) {
310+
updateTag(`userTask/${userTaskId}`);
311+
updateTag(`space/${spaceId}/tasks`);
312+
} else {
313+
revalidateTag(`userTask/${userTaskId}`, 'max');
314+
revalidateTag(`space/${spaceId}/tasks`, 'max');
315+
}
300316
} catch (e) {
301317
const message = getErrorMessage(e);
302318
return userError(message);

src/management-system-v2/lib/use-user-tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function useUserTasks(
7777
}
7878
}
7979

80-
return { userTasks };
80+
return { userTasks, refetch: query.refetch };
8181
}
8282

8383
export default useUserTasks;

0 commit comments

Comments
 (0)