Skip to content

Commit

Permalink
chore!: add indexes for servedBy (#33038)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored Oct 28, 2024
1 parent 8188319 commit af361a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
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

0 comments on commit af361a3

Please sign in to comment.