Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX IF EXISTS idx_aibridge_interceptions_session_latest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Serves the AI Bridge sessions list. The list needs one row per session,
-- ordered by the session's latest interception, which an anti-join finds by
-- probing for a newer interception in the same session. Ordering the index by
-- (session_id, initiator_id, started_at DESC, id DESC) makes that probe an
-- index-only lookup, so the ordered scan of the list can stop after LIMIT
-- sessions instead of aggregating every interception.
--
-- Partial on ended_at because the list excludes in-flight interceptions.
CREATE INDEX idx_aibridge_interceptions_session_latest
ON aibridge_interceptions (session_id, initiator_id, started_at DESC, id DESC)
WHERE ended_at IS NOT NULL;
8 changes: 6 additions & 2 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,17 @@ func (q *sqlQuerier) ListAuthorizedAIBridgeSessions(ctx context.Context, arg Lis
}

query := fmt.Sprintf("-- name: ListAuthorizedAIBridgeSessions :many\n%s", filtered)
// Argument order matches the placeholders in the generated
// listAIBridgeSessions query.
rows, err := q.db.QueryContext(ctx, query,
arg.AfterSessionID,
arg.StartedAfter,
arg.StartedBefore,
arg.InitiatorID,
arg.Provider,
arg.ProviderName,
arg.Model,
arg.Client,
arg.InitiatorID,
arg.SessionID,
arg.Offset,
arg.Limit,
Expand Down Expand Up @@ -1095,14 +1097,16 @@ func (q *sqlQuerier) CountAuthorizedAIBridgeSessions(ctx context.Context, arg Co
}

query := fmt.Sprintf("-- name: CountAuthorizedAIBridgeSessions :one\n%s", filtered)
// Argument order matches the placeholders in the generated
// countAIBridgeSessions query.
rows, err := q.db.QueryContext(ctx, query,
arg.StartedAfter,
arg.StartedBefore,
arg.InitiatorID,
arg.Provider,
arg.ProviderName,
arg.Model,
arg.Client,
arg.InitiatorID,
arg.SessionID,
)
if err != nil {
Expand Down
16 changes: 13 additions & 3 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading