Changeset 0.26.0 (#165)

This commit is contained in:
2026-03-10 13:38:01 +00:00
parent dbc1a97343
commit 400f7dd176
48 changed files with 4923 additions and 208 deletions

View File

@@ -3,6 +3,7 @@ package postgres
import (
"context"
"database/sql"
"time"
"git.gobha.me/xcaliber/chat-switchboard/models"
)
@@ -87,6 +88,21 @@ func (s *SessionStore) Delete(ctx context.Context, id string) error {
return nil
}
// DeleteExpired removes sessions created before olderThan whose channel
// has no messages. Returns the count of deleted rows.
func (s *SessionStore) DeleteExpired(ctx context.Context, olderThan time.Time) (int64, error) {
res, err := DB.ExecContext(ctx, `
DELETE FROM session_participants sp
WHERE sp.created_at < $1
AND NOT EXISTS (
SELECT 1 FROM messages m WHERE m.channel_id = sp.channel_id
)`, olderThan)
if err != nil {
return 0, err
}
return res.RowsAffected()
}
// nullText returns nil for empty strings.
func nullText(s string) interface{} {
if s == "" {