@@ -255,7 +255,7 @@ public function deleteSession(int $sessionId): JSONResponse {
255255 }
256256
257257 try {
258- $ this -> deleteSessionTasks ( $ this -> userId , $ sessionId );
258+ // we don't delete the tasks
259259 $ this ->sessionMapper ->deleteSession ($ this ->userId , $ sessionId );
260260 $ this ->messageMapper ->deleteMessagesBySession ($ sessionId );
261261 return new JSONResponse ();
@@ -265,27 +265,6 @@ public function deleteSession(int $sessionId): JSONResponse {
265265 }
266266 }
267267
268- private function deleteSessionTasks (string $ userId , int $ sessionId ): void {
269- $ sessionExists = $ this ->sessionMapper ->exists ($ this ->userId , $ sessionId );
270- if (!$ sessionExists ) {
271- return ;
272- }
273- $ messages = $ this ->messageMapper ->getMessages ($ sessionId , 0 , 0 );
274- foreach ($ messages as $ message ) {
275- $ ocpTaskId = $ message ->getOcpTaskId ();
276- if ($ ocpTaskId !== 0 ) {
277- try {
278- $ task = $ this ->taskProcessingManager ->getTask ($ ocpTaskId );
279- $ this ->taskProcessingManager ->deleteTask ($ task );
280- } catch (\OCP \TaskProcessing \Exception \Exception ) {
281- // silent failure here because:
282- // if the task is not found: all good nothing to delete
283- // if the task couldn't be deleted, it will be deleted by the task processing cleanup job later anyway
284- }
285- }
286- }
287- }
288-
289268 /**
290269 * Get chat sessions
291270 *
@@ -493,18 +472,10 @@ public function deleteMessage(int $messageId, int $sessionId): JSONResponse {
493472 return new JSONResponse (['error ' => $ this ->l10n ->t ('Session not found ' )], Http::STATUS_NOT_FOUND );
494473 }
495474 $ message = $ this ->messageMapper ->getMessageById ($ sessionId , $ messageId );
496- $ ocpTaskId = $ message ->getOcpTaskId ();
497475
476+ // do not delete the related task
498477 $ this ->messageMapper ->deleteMessageById ($ sessionId , $ messageId );
499478
500- // delete the related task
501- if ($ ocpTaskId !== 0 ) {
502- try {
503- $ task = $ this ->taskProcessingManager ->getTask ($ ocpTaskId );
504- $ this ->taskProcessingManager ->deleteTask ($ task );
505- } catch (\OCP \TaskProcessing \Exception \Exception ) {
506- }
507- }
508479 return new JSONResponse ();
509480 } catch (\OCP \DB \Exception |\RuntimeException $ e ) {
510481 $ this ->logger ->warning ('Failed to delete a chat message ' , ['exception ' => $ e ]);
@@ -688,24 +659,15 @@ public function regenerateForSession(int $sessionId, int $messageId): JSONRespon
688659 }
689660
690661 $ message = $ this ->messageMapper ->getMessageById ($ sessionId , $ messageId );
691- $ ocpTaskId = $ message ->getOcpTaskId ();
692662
663+ // we don't delete the related task
693664 try {
694665 $ this ->messageMapper ->deleteMessageById ($ sessionId , $ messageId );
695666 } catch (\OCP \DB \Exception |\RuntimeException $ e ) {
696667 $ this ->logger ->warning ('Failed to delete the last message ' , ['exception ' => $ e ]);
697668 return new JSONResponse (['error ' => $ this ->l10n ->t ('Failed to delete the last message ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
698669 }
699670
700- // delete the related task
701- if ($ ocpTaskId !== 0 ) {
702- try {
703- $ task = $ this ->taskProcessingManager ->getTask ($ ocpTaskId );
704- $ this ->taskProcessingManager ->deleteTask ($ task );
705- } catch (\OCP \TaskProcessing \Exception \Exception ) {
706- }
707- }
708-
709671 return $ this ->generateForSession ($ sessionId );
710672 }
711673
0 commit comments