Delete all GUI chat sessions and messages for one user.
(user_id: str)
| 511 | |
| 512 | |
| 513 | def clear_chat_sessions(user_id: str) -> int: |
| 514 | """Delete all GUI chat sessions and messages for one user.""" |
| 515 | normalized_user_id = _normalize_identifier(user_id) |
| 516 | if not normalized_user_id: |
| 517 | raise ValueError("user_id is required") |
| 518 | |
| 519 | ensure_chat_tables() |
| 520 | conn = get_connection() |
| 521 | cursor = conn.cursor() |
| 522 | count_row = cursor.execute( |
| 523 | "SELECT COUNT(*) AS count FROM chat_sessions WHERE user_id = ?", |
| 524 | (normalized_user_id,), |
| 525 | ).fetchone() |
| 526 | deleted = int(count_row["count"] if count_row else 0) |
| 527 | cursor.execute("DELETE FROM chat_messages WHERE user_id = ?", (normalized_user_id,)) |
| 528 | cursor.execute("DELETE FROM chat_sessions WHERE user_id = ?", (normalized_user_id,)) |
| 529 | conn.commit() |
| 530 | conn.close() |
| 531 | return deleted |
| 532 | |
| 533 | |
| 534 | # ============== Profile Operations ============== |
nothing calls this directly
no test coverage detected