[PR #27] [MERGED] Replace client session object maps with lru-cache #92

Closed
opened 2026-02-27 04:59:09 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/guyzyl/whatsapp-contact-sync/pull/27
Author: @guyzyl
Created: 12/9/2022
Status: Merged
Merged: 12/9/2022
Merged by: @guyzyl

Base: mainHead: introduce-better-serverside-caching


📝 Commits (1)

  • e330d82 Replace client session object maps with lru-cache

📊 Changes

6 files changed (+169 additions, -163 deletions)

View changed files

📝 server/package-lock.json (+116 -93)
📝 server/package.json (+10 -9)
📝 server/routes/api.ts (+15 -54)
server/src/cache.ts (+18 -0)
📝 server/src/sync.ts (+6 -6)
📝 server/src/whatsapp.ts (+4 -1)

📄 Description

In the previous implementation, a WS is created for every client. The WS is saved in a session id to WS map, and from there is passed to the functions that require it when called.
This PR fixes a bug where in some cases the WS is recreated (for some reasons), causing the WS that was passed to the functions to be outdated and for the service to function as intended (for example, not redirecting after a successful WhatsApp authentication).

To fix this issue, better session caching is introduced by using the lru-cache package.
Now, instead of saving all of the session objects to separate maps, a central cache is used.
This fixes some bugs, makes the code cleaner, and removes a lot of code (which is always great).

This PR should fix #22 .


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/guyzyl/whatsapp-contact-sync/pull/27 **Author:** [@guyzyl](https://github.com/guyzyl) **Created:** 12/9/2022 **Status:** ✅ Merged **Merged:** 12/9/2022 **Merged by:** [@guyzyl](https://github.com/guyzyl) **Base:** `main` ← **Head:** `introduce-better-serverside-caching` --- ### 📝 Commits (1) - [`e330d82`](https://github.com/guyzyl/whatsapp-contact-sync/commit/e330d8223677b62874dc2d2d2202c537e7c3b075) Replace client session object maps with lru-cache ### 📊 Changes **6 files changed** (+169 additions, -163 deletions) <details> <summary>View changed files</summary> 📝 `server/package-lock.json` (+116 -93) 📝 `server/package.json` (+10 -9) 📝 `server/routes/api.ts` (+15 -54) ➕ `server/src/cache.ts` (+18 -0) 📝 `server/src/sync.ts` (+6 -6) 📝 `server/src/whatsapp.ts` (+4 -1) </details> ### 📄 Description In the previous implementation, a WS is created for every client. The WS is saved in a session id to WS map, and from there is passed to the functions that require it when called. This PR fixes a bug where in some cases the WS is recreated (for some reasons), causing the WS that was passed to the functions to be outdated and for the service to function as intended (for example, not redirecting after a successful WhatsApp authentication). To fix this issue, better session caching is introduced by using the [`lru-cache`](https://github.com/isaacs/node-lru-cache) package. Now, instead of saving all of the session objects to separate maps, a central cache is used. This fixes some bugs, makes the code cleaner, and removes a lot of code (which is always great). This PR should fix #22 . --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 04:59:09 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/whatsapp-contact-sync#92
No description provided.