@@ -34,7 +34,7 @@ import { getProcessBPMN, getProcessHtmlFormHTML } from '../data/processes';
3434import { saveInstanceArtifact } from '../data/file-manager-facade' ;
3535import { getDBInstance } from '@/lib/data/instance' ;
3636import Ability from '../ability/abilityHelper' ;
37- import { revalidateTag } from 'next/cache' ;
37+ import { revalidateTag , updateTag } from 'next/cache' ;
3838
3939export 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 ) ;
0 commit comments