fix(proxy): filter out old connections

This commit is contained in:
Viren070
2025-11-02 13:05:49 +00:00
parent 3989dde254
commit 950c3d0680
+26 -2
View File
@@ -180,6 +180,7 @@ export class BuiltinProxyStats {
);
private static ACTIVE_THRESHOLD = 6 * 60 * 60 * 1000; // 6 hours
private static HISTORY_RETENTION = 7 * 24 * 60 * 60 * 1000; // 7 days
constructor() {}
@@ -261,7 +262,30 @@ export class BuiltinProxyStats {
public async getConnectionHistory(user: string): Promise<ConnectionRecord[]> {
const encryptedData = await this.connectionHistory.get(user);
return encryptedData ? this.decryptConnectionRecords(encryptedData) : [];
if (!encryptedData) {
return [];
}
const connections = this.decryptConnectionRecords(encryptedData);
const now = Date.now();
const cutoffTime = now - BuiltinProxyStats.HISTORY_RETENTION;
// Filter out records older than HISTORY_RETENTION
const recentConnections = connections.filter(
(conn) => conn.lastSeen > cutoffTime
);
// If any records were filtered out, update the cache
if (recentConnections.length < connections.length) {
await this.connectionHistory.set(
user,
this.encryptConnectionRecords(recentConnections),
BuiltinProxyStats.HISTORY_RETENTION,
true
);
}
return recentConnections;
}
public async addConnection(
@@ -310,7 +334,7 @@ export class BuiltinProxyStats {
await this.connectionHistory.set(
user,
this.encryptConnectionRecords(historyConnections),
7 * 24 * 60 * 60,
BuiltinProxyStats.HISTORY_RETENTION,
true
);
} else {