feat(chat): add batch management for conversations
This commit is contained in:
@@ -87,3 +87,11 @@ func (r *sessionRepository) Update(ctx context.Context, session *types.Session)
|
||||
func (r *sessionRepository) Delete(ctx context.Context, tenantID uint64, id string) error {
|
||||
return r.db.WithContext(ctx).Where("tenant_id = ?", tenantID).Delete(&types.Session{}, "id = ?", id).Error
|
||||
}
|
||||
|
||||
// BatchDelete deletes multiple sessions by IDs
|
||||
func (r *sessionRepository) BatchDelete(ctx context.Context, tenantID uint64, ids []string) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.db.WithContext(ctx).Where("tenant_id = ? AND id IN ?", tenantID, ids).Delete(&types.Session{}).Error
|
||||
}
|
||||
|
||||
@@ -225,6 +225,38 @@ func (s *sessionService) DeleteSession(ctx context.Context, id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BatchDeleteSessions deletes multiple sessions by IDs
|
||||
func (s *sessionService) BatchDeleteSessions(ctx context.Context, ids []string) error {
|
||||
if len(ids) == 0 {
|
||||
logger.Error(ctx, "Failed to batch delete sessions: IDs list is empty")
|
||||
return errors.New("session ids are required")
|
||||
}
|
||||
|
||||
// Get tenant ID from context
|
||||
tenantID := ctx.Value(types.TenantIDContextKey).(uint64)
|
||||
|
||||
// Cleanup associated resources for each session
|
||||
for _, id := range ids {
|
||||
if err := s.webSearchStateRepo.DeleteWebSearchTempKBState(ctx, id); err != nil {
|
||||
logger.Warnf(ctx, "Failed to cleanup temporary KB for session %s: %v", id, err)
|
||||
}
|
||||
if err := s.sessionStorage.Delete(ctx, id); err != nil {
|
||||
logger.Warnf(ctx, "Failed to cleanup conversation context for session %s: %v", id, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Batch delete sessions from repository
|
||||
if err := s.sessionRepo.BatchDelete(ctx, tenantID, ids); err != nil {
|
||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
||||
"session_ids": ids,
|
||||
"tenant_id": tenantID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GenerateTitle generates a title for the current conversation content
|
||||
// modelID: optional model ID to use for title generation (if empty, uses first available KnowledgeQA model)
|
||||
func (s *sessionService) GenerateTitle(ctx context.Context,
|
||||
|
||||
Reference in New Issue
Block a user