Skip to content

Cache optimization#34868

Open
user312222 wants to merge 2 commits into
RocketChat:developfrom
user312222:cache-optimization
Open

Cache optimization#34868
user312222 wants to merge 2 commits into
RocketChat:developfrom
user312222:cache-optimization

Conversation

@user312222
Copy link
Copy Markdown

feat: Add userCache.ts for cache optimization

This Pull Request adds a new userCache.ts file to make the application faster and more efficient. It uses a simple Map to store user data in memory, so the database is not called every time. This reduces the load on the database and makes the application respond quicker. The cache is also updated when needed to keep the data correct and up-to-date. This change helps the application handle more users without slowing down.

Changes:

  • Added a new userCache.ts file to implement a Map-based caching mechanism.
  • Integrated the caching logic into user-related service functions.
  • Updated related test cases to include cache validation.

Tests:

  • All existing tests pass successfully.
  • Added new tests for the userCache.ts functionality.

Notes:

  • Please review the integration with UsersRaw for potential optimization.
  • Suggestions for further improvements are welcome.

@user312222 user312222 requested a review from a team as a code owner January 3, 2025 13:53
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Jan 3, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project
  • This PR has an invalid title

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 3, 2025

🦋 Changeset detected

Latest commit: 03c3257

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
@rocket.chat/meteor Major
@rocket.chat/core-typings Major
@rocket.chat/rest-typings Major
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/gazzodown Major
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-contexts Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/ui-avatar Major
@rocket.chat/ui-client Major
@rocket.chat/ui-video-conf Major
@rocket.chat/ui-voip Major
@rocket.chat/web-ui-registration Major
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 3, 2025

CLA assistant check
All committers have signed the CLA.

@@ -0,0 +1,30 @@
import { UsersRaw } from '../../../../packages/models/src/models/Users.js';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if one instance deletes an user?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user deletes their account but the cache is not cleared, the system might still use old cache data, leading to "user not found" errors when a new account is created. To solve this, it's good to have a command to clear the cache when this error occurs, but an automated system to refresh the cache during account deletion or after some time would be more efficient and user-friendly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but what if one instance reads the cache while the 'clear command' is being ran?
NOTE: clearing an object in JS is not an atomic operation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should implement an ACID compliant cache just for this, lets defer to the database to ensure correctness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants