@@ -13,7 +13,6 @@ export async function sendUpdateViaWebsocket(
1313 userId : string ,
1414 message : WebSocketMessage ,
1515 options : {
16- databaseId ?: string // Optional filter by database
1716 failSilently ?: boolean // Whether to fail silently on errors
1817 maxRetries ?: number // Maximum number of retries per connection
1918 } = { }
@@ -23,22 +22,15 @@ export async function sendUpdateViaWebsocket(
2322 totalConnections : number
2423 errors : Array < { connectionId : string ; error : string } >
2524} > {
26- const { databaseId , failSilently = true , maxRetries = 2 } = options
25+ const { failSilently = true , maxRetries = 2 } = options
2726
2827 try {
2928 console . log ( `📡 Fetching active websocket connections for user: ${ userId } ` )
3029
31- // Build query for user connections
32- let query = webSocketConnections . query . byUser ( {
30+ // Build query for user connections using primary index (all assumed active since we delete disconnected ones)
31+ const connections = await webSocketConnections . query . primary ( {
3332 user_id : userId ,
34- } ) . where ( ( { status } , { eq } ) => eq ( status , 'connected' ) )
35-
36- // Add database filter if specified
37- if ( databaseId ) {
38- query = query . where ( ( { database_id } , { eq } ) => eq ( database_id , databaseId ) )
39- }
40-
41- const connections = await query . go ( )
33+ } ) . go ( )
4234 const activeConnections = connections . data
4335
4436 console . log ( `🔍 Found ${ activeConnections . length } active connections for user ${ userId } ` )
@@ -211,7 +203,6 @@ export async function sendChatUpdateViaWebsocket(
211203 options : {
212204 threadId ?: string
213205 executionId ?: string
214- databaseId ?: string
215206 failSilently ?: boolean
216207 } = { }
217208) : Promise < {
@@ -226,13 +217,11 @@ export async function sendChatUpdateViaWebsocket(
226217 payload,
227218 executionId : options . executionId ,
228219 metadata : {
229- threadId : options . threadId ,
230- databaseId : options . databaseId
220+ threadId : options . threadId
231221 }
232222 }
233223
234224 return sendUpdateViaWebsocket ( userId , message , {
235- databaseId : options . databaseId ,
236225 failSilently : options . failSilently
237226 } )
238227}
0 commit comments