v0.2.0 1301099

sseConnectionTracker.ts RawHistoryFolder

1import { createLogger } from './utils/logger.server';
2
3const log = createLogger('sse-connection-tracker');
4
5interface ConnectionInfo {
6    userId: string;
7    connectedAt: number;
8    lastActivity: number;
9}
10
11class SSEConnectionTracker {
12    private connections = new Map<string, ConnectionInfo>();
13    
14    addConnection(userId: string): boolean {
15        const existing = this.connections.get(userId);
16        if (existing) {
17            log.debug('User already has active connection', { userId });
18            // Update last activity but don't trigger status update
19            existing.lastActivity = Date.now();
20            return false; // Connection already exists
21        }
22        
23        this.connections.set(userId, {
24            userId,
25            connectedAt: Date.now(),
26            lastActivity: Date.now()
27        });
28        
29        log.debug('New SSE connection tracked', { 
30            userId, 
31            totalConnections: this.connections.size 
32        });
33        return true; // New connection
34    }
35    
36    removeConnection(userId: string): boolean {
37        const deleted = this.connections.delete(userId);
38        if (deleted) {
39            log.debug('SSE connection removed', { 
40                userId, 
41                remainingConnections: this.connections.size 
42            });
43        }
44        return deleted;
45    }
46    
47    hasConnection(userId: string): boolean {
48        return this.connections.has(userId);
49    }
50    
51    updateActivity(userId: string): void {
52        const connection = this.connections.get(userId);
53        if (connection) {
54            connection.lastActivity = Date.now();
55        }
56    }
57    
58    getActiveUserIds(): string[] {
59        return Array.from(this.connections.keys());
60    }
61    
62    getConnectionCount(): number {
63        return this.connections.size;
64    }
65    
66    // Clean up stale connections (e.g., if server didn't properly close them)
67    cleanupStaleConnections(maxInactivityMs: number = 5 * 60 * 1000): string[] {
68        const now = Date.now();
69        const staleUserIds: string[] = [];
70        
71        for (const [userId, info] of this.connections.entries()) {
72            if (now - info.lastActivity > maxInactivityMs) {
73                this.connections.delete(userId);
74                staleUserIds.push(userId);
75            }
76        }
77        
78        if (staleUserIds.length > 0) {
79            log.info('Cleaned up stale connections', { 
80                count: staleUserIds.length,
81                userIds: staleUserIds
82            });
83        }
84        
85        return staleUserIds;
86    }
87}
88
89// Export singleton instance
90export const sseConnectionTracker = new SSEConnectionTracker();

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 9

↑↓ moveenter openesc close