Skip to content

Commit

Permalink
chore: Increase cache time to 10s on getUnits function (#30285)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Sep 6, 2023
1 parent e6d92ff commit ace3599
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-birds-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

chore: Increase cache time from 5s to 10s on `getUnits` helpers. This should reduce the number of DB calls made by this method to fetch the unit limitations for a user.
2 changes: 1 addition & 1 deletion apps/meteor/ee/app/livechat-enterprise/server/lib/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function hasUnits(): Promise<boolean> {
}

// Units should't change really often, so we can cache the result
const memoizedHasUnits = mem(hasUnits, { maxAge: 5000 });
const memoizedHasUnits = mem(hasUnits, { maxAge: 10000 });

export async function getUnitsFromUser(): Promise<{ [k: string]: any }[] | undefined> {
if (!(await memoizedHasUnits())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function getUnitsFromUserRoles(user: string | null): Promise<string[] | un
return LivechatUnit.findByMonitorId(user);
}

const memoizedGetUnitFromUserRoles = mem(getUnitsFromUserRoles, { maxAge: 5000 });
const memoizedGetUnitFromUserRoles = mem(getUnitsFromUserRoles, { maxAge: 10000 });

declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down

0 comments on commit ace3599

Please sign in to comment.