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

chore!: add indexes for servedBy #33038

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/eleven-chefs-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@rocket.chat/meteor': major
---

Remove support of filtering by agent's username on the following endpoint:

- `/v1/livechat/rooms`

The performance of the endpoint was improved when filtering by:

- Agent
- Deparment
- Open chats
13 changes: 6 additions & 7 deletions apps/meteor/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
{ key: { servedBy: 1 }, sparse: true },
{ key: { 'v.token': 1, 'email.thread': 1 }, sparse: true },
{ key: { 'v._id': 1 }, sparse: true },
{ key: { 'servedBy._id': 1, 'departmentId': 1, 't': 1, 'open': 1, 'ts': -1 } },
{ key: { t: 1, departmentId: 1, closedAt: 1 }, partialFilterExpression: { closedAt: { $exists: true } } },
{ key: { source: 1 }, sparse: true },
{ key: { departmentAncestors: 1 }, sparse: true },
Expand Down Expand Up @@ -755,7 +756,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
const match: Document = {
$match: {
't': 'l',
'servedBy.username': { $exists: true },
'servedBy._id': { $exists: true },
'open': true,
'$or': [
{
Expand Down Expand Up @@ -789,7 +790,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
const match: Document = {
$match: {
't': 'l',
'servedBy.username': { $exists: true },
'servedBy._id': { $exists: true },
'open': true,
'onHold': {
$exists: true,
Expand All @@ -815,7 +816,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
$match: {
't': 'l',
'open': { $exists: false },
'servedBy.username': { $exists: true },
'servedBy._id': { $exists: true },
'ts': { $gte: new Date(start) },
'closedAt': { $lte: new Date(end) },
},
Expand Down Expand Up @@ -1072,7 +1073,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
't': 'l',
'ts': { $gte: new Date(start), $lte: new Date(end) },
'responseBy.lastMessageTs': { $exists: true },
'servedBy.ts': { $exists: true },
'servedBy._id': { $exists: true },
},
};
const group = {
Expand Down Expand Up @@ -1276,9 +1277,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
const query: Filter<IOmnichannelRoom> = {
t: 'l',
...extraQuery,
...(agents && {
$or: [{ 'servedBy._id': { $in: agents } }, { 'servedBy.username': { $in: agents } }],
}),
...(agents && { 'servedBy._id': { $in: agents } }),
...(roomName && { fname: new RegExp(escapeRegExp(roomName), 'i') }),
...(departmentId && departmentId !== 'undefined' && { departmentId }),
...(open !== undefined && { open: { $exists: open }, onHold: { $ne: true } }),
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/models/raw/VoipRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class VoipRoomRaw extends BaseRaw<IVoipRoom> implements IVoipRoomModel {
const query: Filter<IVoipRoom> = {
t: 'v',
...(visitorId && visitorId !== 'undefined' && { 'v._id': visitorId }),
...(agents && { $or: [{ 'servedBy._id': { $in: agents } }, { 'servedBy.username': { $in: agents } }] }),
...(agents && { 'servedBy._id': { $in: agents } }),
};

if (open !== undefined) {
Expand Down
Loading