Revert "fix: convert socket sessions to cacheHandler"

This reverts commit 733aee3977.
This commit is contained in:
DecDuck
2025-05-08 21:43:54 +10:00
parent 0f773a9779
commit 2fb909f73d
2 changed files with 13 additions and 13 deletions

View File

@ -1,9 +1,9 @@
import notificationSystem from "~/server/internal/notifications";
import aclManager from "~/server/internal/acls";
import cacheHandler from "~/server/internal/cache";
// TODO add web socket sessions for horizontal scaling
// Peer ID to user ID
const socketSessions = cacheHandler.createCache<string>("notificationSocketSessions");
const socketSessions = new Map<string, string>();
export default defineWebSocketHandler({
async open(peer) {
@ -23,7 +23,7 @@ export default defineWebSocketHandler({
userIds.push("system");
}
await socketSessions.set(peer.id, userId);
socketSessions.set(peer.id, userId);
for (const listenUserId of userIds) {
notificationSystem.listen(listenUserId, peer.id, (notification) => {
@ -32,7 +32,7 @@ export default defineWebSocketHandler({
}
},
async close(peer, _details) {
const userId = await socketSessions.get(peer.id);
const userId = socketSessions.get(peer.id);
if (!userId) {
console.log(`skipping websocket close for ${peer.id}`);
return;
@ -40,6 +40,6 @@ export default defineWebSocketHandler({
notificationSystem.unlisten(userId, peer.id);
notificationSystem.unlisten("system", peer.id); // In case we were listening as 'system'
await socketSessions.remove(peer.id);
socketSessions.delete(peer.id);
},
});