DeleteByChatID deletes debug data for a chat and emits a delete event. The startedBefore bound scopes deletion to runs created before that instant so that retried cleanup does not remove runs created by a replacement turn that raced ahead of the retry window (for example, an unarchive that fires bet
( ctx context.Context, chatID uuid.UUID, startedBefore time.Time, )
| 529 | // an unarchive that fires between the initial archive-cleanup attempt |
| 530 | // and its retry). |
| 531 | func (s *Service) DeleteByChatID( |
| 532 | ctx context.Context, |
| 533 | chatID uuid.UUID, |
| 534 | startedBefore time.Time, |
| 535 | ) (int64, error) { |
| 536 | deleted, err := s.db.DeleteChatDebugDataByChatID( |
| 537 | chatdContext(ctx), |
| 538 | database.DeleteChatDebugDataByChatIDParams{ |
| 539 | ChatID: chatID, |
| 540 | StartedBefore: startedBefore, |
| 541 | }, |
| 542 | ) |
| 543 | if err != nil { |
| 544 | return 0, err |
| 545 | } |
| 546 | |
| 547 | s.publishEvent(ctx, chatID, EventKindDelete, uuid.Nil, uuid.Nil) |
| 548 | return deleted, nil |
| 549 | } |
| 550 | |
| 551 | // DeleteAfterMessageID deletes debug data newer than the given message. |
| 552 | // The startedBefore bound scopes deletion to runs created before that |