style: format SSE files with prettier
- commit
- e52fcc07b29eff722070620a36b3b24906cb86bd
- author
- Kit · · 2025-12-15 10:50 UTC
- parent
- 6c2663e
- signature
- SSH Unverified
SHA256:H91DFuEG4jpk5edzLA4aUKkpv4zv9Q339ipRmkph6TkThe key is unknown
3 files · +18 -13
M src/lib/sse/SSEClient.svelte.ts +1 -3
| @@ -241,9 +241,7 @@ export class SSEClient { | |||
| 241 | 241 | this._reconnectAttempts++; | |
| 242 | 242 | ||
| 243 | 243 | const delay = this.calculateBackoff(); | |
| 244 | - | console.debug( | |
| 245 | - | `[SSEClient] Reconnecting in ${delay}ms (attempt ${this._reconnectAttempts})` | |
| 246 | - | ); | |
| 244 | + | console.debug(`[SSEClient] Reconnecting in ${delay}ms (attempt ${this._reconnectAttempts})`); | |
| 247 | 245 | ||
| 248 | 246 | this.reconnectTimer = setTimeout(() => { | |
| 249 | 247 | this.connect(); | |
| @@ -241,9 +241,7 @@ export class SSEClient { | |||||
| 241 | this._reconnectAttempts++; | 241 | this._reconnectAttempts++; | ||
| 242 | 242 | ||||
| 243 | const delay = this.calculateBackoff(); | 243 | const delay = this.calculateBackoff(); | ||
| 244 | - | console.debug( | 244 | + | console.debug(`[SSEClient] Reconnecting in ${delay}ms (attempt ${this._reconnectAttempts})`); |
| 245 | - | `[SSEClient] Reconnecting in ${delay}ms (attempt ${this._reconnectAttempts})` | |||
| 246 | - | ); | |||
| 247 | 245 | ||||
| 248 | this.reconnectTimer = setTimeout(() => { | 246 | this.reconnectTimer = setTimeout(() => { | ||
| 249 | this.connect(); | 247 | this.connect(); | ||
M src/lib/sse/SSEManager.ts +10 -2
| @@ -136,7 +136,11 @@ class SSEManager { | |||
| 136 | 136 | * Remove a connection | |
| 137 | 137 | * @returns Whether this was the last connection for the user | |
| 138 | 138 | */ | |
| 139 | - | removeConnection(connectionId: string): { removed: boolean; isLastConnection: boolean; userId: string | null } { | |
| 139 | + | removeConnection(connectionId: string): { | |
| 140 | + | removed: boolean; | |
| 141 | + | isLastConnection: boolean; | |
| 142 | + | userId: string | null; | |
| 143 | + | } { | |
| 140 | 144 | const connection = this.connections.get(connectionId); | |
| 141 | 145 | if (!connection) { | |
| 142 | 146 | return { removed: false, isLastConnection: false, userId: null }; | |
| @@ -360,7 +364,11 @@ class SSEManager { | |||
| 360 | 364 | /** | |
| 361 | 365 | * Get connection statistics | |
| 362 | 366 | */ | |
| 363 | - | getStats(): { totalConnections: number; uniqueUsers: number; queueStats: { rooms: number; totalMessages: number } } { | |
| 367 | + | getStats(): { | |
| 368 | + | totalConnections: number; | |
| 369 | + | uniqueUsers: number; | |
| 370 | + | queueStats: { rooms: number; totalMessages: number }; | |
| 371 | + | } { | |
| 364 | 372 | return { | |
| 365 | 373 | totalConnections: this.connections.size, | |
| 366 | 374 | uniqueUsers: this.userConnections.size, | |
| @@ -136,7 +136,11 @@ class SSEManager { | |||||
| 136 | * Remove a connection | 136 | * Remove a connection | ||
| 137 | * @returns Whether this was the last connection for the user | 137 | * @returns Whether this was the last connection for the user | ||
| 138 | */ | 138 | */ | ||
| 139 | - | removeConnection(connectionId: string): { removed: boolean; isLastConnection: boolean; userId: string | null } { | 139 | + | removeConnection(connectionId: string): { |
| 140 | + | removed: boolean; | |||
| 141 | + | isLastConnection: boolean; | |||
| 142 | + | userId: string | null; | |||
| 143 | + | } { | |||
| 140 | const connection = this.connections.get(connectionId); | 144 | const connection = this.connections.get(connectionId); | ||
| 141 | if (!connection) { | 145 | if (!connection) { | ||
| 142 | return { removed: false, isLastConnection: false, userId: null }; | 146 | return { removed: false, isLastConnection: false, userId: null }; | ||
| @@ -360,7 +364,11 @@ class SSEManager { | |||||
| 360 | /** | 364 | /** | ||
| 361 | * Get connection statistics | 365 | * Get connection statistics | ||
| 362 | */ | 366 | */ | ||
| 363 | - | getStats(): { totalConnections: number; uniqueUsers: number; queueStats: { rooms: number; totalMessages: number } } { | 367 | + | getStats(): { |
| 368 | + | totalConnections: number; | |||
| 369 | + | uniqueUsers: number; | |||
| 370 | + | queueStats: { rooms: number; totalMessages: number }; | |||
| 371 | + | } { | |||
| 364 | return { | 372 | return { | ||
| 365 | totalConnections: this.connections.size, | 373 | totalConnections: this.connections.size, | ||
| 366 | uniqueUsers: this.userConnections.size, | 374 | uniqueUsers: this.userConnections.size, | ||
M src/routes/api/sse/+server.ts +7 -8
| @@ -64,12 +64,7 @@ function startTimeoutCheck() { | |||
| 64 | 64 | status: 'offline', | |
| 65 | 65 | lastSeen: now | |
| 66 | 66 | }) | |
| 67 | - | .where( | |
| 68 | - | and( | |
| 69 | - | ne(users.status, 'offline'), | |
| 70 | - | lt(users.lastSeen, timeoutThreshold) | |
| 71 | - | ) | |
| 72 | - | ) | |
| 67 | + | .where(and(ne(users.status, 'offline'), lt(users.lastSeen, timeoutThreshold))) | |
| 73 | 68 | .returning({ | |
| 74 | 69 | id: users.id, | |
| 75 | 70 | nickname: users.nickname, | |
| @@ -347,7 +342,11 @@ export const GET: RequestHandler = async ({ request, locals }) => { | |||
| 347 | 342 | if (cleanupListener) cleanupListener(); | |
| 348 | 343 | ||
| 349 | 344 | const maskedUserId = userId.slice(0, 8); | |
| 350 | - | log.info('Connection closed', { userId: maskedUserId, connectionId: connectionId?.slice(0, 8), reason }); | |
| 345 | + | log.info('Connection closed', { | |
| 346 | + | userId: maskedUserId, | |
| 347 | + | connectionId: connectionId?.slice(0, 8), | |
| 348 | + | reason | |
| 349 | + | }); | |
| 351 | 350 | ||
| 352 | 351 | // Remove connection from manager | |
| 353 | 352 | const { isLastConnection } = sseManager.removeConnection(connectionId); | |
| @@ -379,7 +378,7 @@ export const GET: RequestHandler = async ({ request, locals }) => { | |||
| 379 | 378 | headers: { | |
| 380 | 379 | 'Content-Type': 'text/event-stream', | |
| 381 | 380 | 'Cache-Control': 'no-cache', | |
| 382 | - | 'Connection': 'keep-alive', | |
| 381 | + | Connection: 'keep-alive', | |
| 383 | 382 | 'X-Accel-Buffering': 'no' // Disable nginx buffering | |
| 384 | 383 | } | |
| 385 | 384 | }); | |
| @@ -64,12 +64,7 @@ function startTimeoutCheck() { | |||||
| 64 | status: 'offline', | 64 | status: 'offline', | ||
| 65 | lastSeen: now | 65 | lastSeen: now | ||
| 66 | }) | 66 | }) | ||
| 67 | - | .where( | 67 | + | .where(and(ne(users.status, 'offline'), lt(users.lastSeen, timeoutThreshold))) |
| 68 | - | and( | |||
| 69 | - | ne(users.status, 'offline'), | |||
| 70 | - | lt(users.lastSeen, timeoutThreshold) | |||
| 71 | - | ) | |||
| 72 | - | ) | |||
| 73 | .returning({ | 68 | .returning({ | ||
| 74 | id: users.id, | 69 | id: users.id, | ||
| 75 | nickname: users.nickname, | 70 | nickname: users.nickname, | ||
| @@ -347,7 +342,11 @@ export const GET: RequestHandler = async ({ request, locals }) => { | |||||
| 347 | if (cleanupListener) cleanupListener(); | 342 | if (cleanupListener) cleanupListener(); | ||
| 348 | 343 | ||||
| 349 | const maskedUserId = userId.slice(0, 8); | 344 | const maskedUserId = userId.slice(0, 8); | ||
| 350 | - | log.info('Connection closed', { userId: maskedUserId, connectionId: connectionId?.slice(0, 8), reason }); | 345 | + | log.info('Connection closed', { |
| 346 | + | userId: maskedUserId, | |||
| 347 | + | connectionId: connectionId?.slice(0, 8), | |||
| 348 | + | reason | |||
| 349 | + | }); | |||
| 351 | 350 | ||||
| 352 | // Remove connection from manager | 351 | // Remove connection from manager | ||
| 353 | const { isLastConnection } = sseManager.removeConnection(connectionId); | 352 | const { isLastConnection } = sseManager.removeConnection(connectionId); | ||
| @@ -379,7 +378,7 @@ export const GET: RequestHandler = async ({ request, locals }) => { | |||||
| 379 | headers: { | 378 | headers: { | ||
| 380 | 'Content-Type': 'text/event-stream', | 379 | 'Content-Type': 'text/event-stream', | ||
| 381 | 'Cache-Control': 'no-cache', | 380 | 'Cache-Control': 'no-cache', | ||
| 382 | - | 'Connection': 'keep-alive', | 381 | + | Connection: 'keep-alive', |
| 383 | 'X-Accel-Buffering': 'no' // Disable nginx buffering | 382 | 'X-Accel-Buffering': 'no' // Disable nginx buffering | ||
| 384 | } | 383 | } | ||
| 385 | }); | 384 | }); | ||