Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Omnichannel making an excessive amount of requests to room.info #29425

Merged
merged 9 commits into from
Jun 21, 2023
5 changes: 5 additions & 0 deletions .changeset/light-toys-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed Omnichannel making an excessive amount of requests to room.info
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const events = {
}

LivechatInquiry.upsert({ _id: inquiry._id }, { ...inquiry, alert: true, _updatedAt: new Date(inquiry._updatedAt) });
await queryClient.invalidateQueries({ queryKey: ['rooms', inquiry.rid], exact: true });
await queryClient.invalidateQueries(['/v1/rooms.info', inquiry.rid]);
},
removed: (inquiry: ILivechatInquiryRecord) => LivechatInquiry.remove(inquiry._id),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import type { IOmnichannelRoom, Serialized } from '@rocket.chat/core-typings';
import { useStream, useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { minutesToMilliseconds } from 'date-fns';
import { useEffect } from 'react';

export const useOmnichannelRoomInfo = (
roomId: string,
{ cacheTime = minutesToMilliseconds(15), staleTime = minutesToMilliseconds(5) } = {},
) => {
const getRoomInfo = useEndpoint('GET', '/v1/rooms.info');
const subscribeToRoom = useStream('room-data');
const queryClient = useQueryClient();

const { data: roomData, ...props } = useQuery(['/v1/rooms.info', roomId], () => getRoomInfo({ roomId }), { cacheTime, staleTime });
const room = roomData?.room as unknown as Serialized<IOmnichannelRoom>;

useEffect(
() =>
subscribeToRoom(roomId, () => {
queryClient.invalidateQueries(['/v1/rooms.info', roomId], { exact: true });
queryClient.invalidateQueries(['/v1/livechat/rooms']);
}),
[queryClient, roomId, subscribeToRoom],
);

return {
data: room,
...props,
Expand Down
14 changes: 10 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9657,14 +9657,14 @@ __metadata:
linkType: hard

"@rocket.chat/fuselage-hooks@npm:next":
version: 0.32.0-dev.243
resolution: "@rocket.chat/fuselage-hooks@npm:0.32.0-dev.243"
version: 0.32.0-dev.274
resolution: "@rocket.chat/fuselage-hooks@npm:0.32.0-dev.274"
dependencies:
use-sync-external-store: ~1.2.0
peerDependencies:
"@rocket.chat/fuselage-tokens": "*"
react: ^17.0.2
checksum: 3a8f2375e3df9d9194efd9e3f70ebeff6dffde07d0b49dc94fbe0a2e5e6b37fbf1d6822ed4d218140479c8ada22545eb74d6b31f764740c04292513e2fc3f0f6
checksum: 32e0872deb05e8b853aed59cab2cc4b3d3a707f0997009170a12b19d252ca09c203f8139b227c90678c0c06e14228c116ab428b9fba81228d1dab981844d8d54
languageName: node
linkType: hard

Expand Down Expand Up @@ -9777,6 +9777,12 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/fuselage@link:../../../fuselage/packages/fuselage::locator=%40rocket.chat%2Fmeteor%40workspace%3Aapps%2Fmeteor":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage@link:../../../fuselage/packages/fuselage::locator=%40rocket.chat%2Fmeteor%40workspace%3Aapps%2Fmeteor"
languageName: node
linkType: soft

"@rocket.chat/fuselage@npm:next":
version: 0.32.0-dev.358
resolution: "@rocket.chat/fuselage@npm:0.32.0-dev.358"
Expand Down Expand Up @@ -10092,7 +10098,7 @@ __metadata:
"@rocket.chat/favicon": "workspace:^"
"@rocket.chat/forked-matrix-appservice-bridge": ^4.0.1
"@rocket.chat/forked-matrix-bot-sdk": ^0.6.0-beta.2
"@rocket.chat/fuselage": next
"@rocket.chat/fuselage": "link:../../../fuselage/packages/fuselage"
"@rocket.chat/fuselage-hooks": next
"@rocket.chat/fuselage-polyfills": next
"@rocket.chat/fuselage-toastbar": next
Expand Down