(ctx context.Context, chatID uuid.UUID)
| 3008 | } |
| 3009 | |
| 3010 | func (p *Server) releaseManualTitleLock(ctx context.Context, chatID uuid.UUID) { |
| 3011 | cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second) |
| 3012 | defer cancel() |
| 3013 | |
| 3014 | err := p.db.InTx(func(tx database.Store) error { |
| 3015 | lockedChat, err := tx.GetChatByIDForUpdate(cleanupCtx, chatID) |
| 3016 | if err != nil { |
| 3017 | return xerrors.Errorf("lock chat to release manual title regeneration: %w", err) |
| 3018 | } |
| 3019 | if !lockedChat.WorkerID.Valid || lockedChat.WorkerID.UUID != manualTitleLockWorkerID { |
| 3020 | return nil |
| 3021 | } |
| 3022 | _, err = updateChatStatusPreserveUpdatedAt( |
| 3023 | cleanupCtx, |
| 3024 | tx, |
| 3025 | lockedChat, |
| 3026 | uuid.NullUUID{}, |
| 3027 | sql.NullTime{}, |
| 3028 | sql.NullTime{}, |
| 3029 | ) |
| 3030 | if err != nil { |
| 3031 | return xerrors.Errorf("clear manual title regeneration marker: %w", err) |
| 3032 | } |
| 3033 | return nil |
| 3034 | }, database.DefaultTXOptions().WithID("chat_title_regenerate_unlock")) |
| 3035 | if err != nil { |
| 3036 | p.logger.Warn(cleanupCtx, "failed to release manual title regeneration marker", |
| 3037 | slog.F("chat_id", chatID), |
| 3038 | slog.Error(err), |
| 3039 | ) |
| 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | // RegenerateChatTitle regenerates a chat title from the chat's visible |
| 3044 | // messages, persists it when it changes, and broadcasts the update. |
no test coverage detected