mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add chat and chat_files cleanup to dbpurge (#23833)
Fixes https://github.com/coder/coder/issues/23910 Adds periodic cleanup of chats and chat files to the dbpurge background goroutine, with a configurable retention period exposed in the Agent settings UI. > 🤖 Written by a Coder Agent. Reviewed by a human.
This commit is contained in:
@@ -545,6 +545,17 @@ type UpdateChatWorkspaceTTLRequest struct {
|
||||
WorkspaceTTLMillis int64 `json:"workspace_ttl_ms"`
|
||||
}
|
||||
|
||||
// ChatRetentionDaysResponse contains the current chat retention setting.
|
||||
type ChatRetentionDaysResponse struct {
|
||||
RetentionDays int32 `json:"retention_days"`
|
||||
}
|
||||
|
||||
// UpdateChatRetentionDaysRequest is a request to update the chat
|
||||
// retention period.
|
||||
type UpdateChatRetentionDaysRequest struct {
|
||||
RetentionDays int32 `json:"retention_days"`
|
||||
}
|
||||
|
||||
// ParseChatWorkspaceTTL parses a stored TTL string, returning the
|
||||
// default when the value is empty.
|
||||
func ParseChatWorkspaceTTL(s string) (time.Duration, error) {
|
||||
@@ -1667,6 +1678,33 @@ func (c *ExperimentalClient) UpdateChatWorkspaceTTL(ctx context.Context, req Upd
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetChatRetentionDays returns the configured chat retention period.
|
||||
func (c *ExperimentalClient) GetChatRetentionDays(ctx context.Context) (ChatRetentionDaysResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/experimental/chats/config/retention-days", nil)
|
||||
if err != nil {
|
||||
return ChatRetentionDaysResponse{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return ChatRetentionDaysResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp ChatRetentionDaysResponse
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
// UpdateChatRetentionDays updates the chat retention period.
|
||||
func (c *ExperimentalClient) UpdateChatRetentionDays(ctx context.Context, req UpdateChatRetentionDaysRequest) error {
|
||||
res, err := c.Request(ctx, http.MethodPut, "/api/experimental/chats/config/retention-days", req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusNoContent {
|
||||
return ReadBodyAsError(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetChatTemplateAllowlist returns the deployment-wide chat template allowlist.
|
||||
func (c *ExperimentalClient) GetChatTemplateAllowlist(ctx context.Context) (ChatTemplateAllowlist, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/experimental/chats/config/template-allowlist", nil)
|
||||
|
||||
Reference in New Issue
Block a user