Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Meteor.methods<ServerMethods>({

// prevent removing last user from admin role
if (role._id === 'admin') {
const adminCount = await Users.col.countDocuments({
const adminCount = await Users.countDocuments({
roles: {
$in: ['admin'],
},
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/federation/server/functions/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { FederationServers, FederationRoomEvents, Users } from '@rocket.chat/mod
import { Meteor } from 'meteor/meteor';

export async function getStatistics() {
const numberOfEvents = await FederationRoomEvents.col.estimatedDocumentCount();
const numberOfEvents = await FederationRoomEvents.estimatedDocumentCount();
const numberOfFederatedUsers = await Users.countRemote();
const numberOfServers = await FederationServers.col.estimatedDocumentCount();
const numberOfServers = await FederationServers.estimatedDocumentCount();

return { numberOfEvents, numberOfFederatedUsers, numberOfServers };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function generateUsernameSuggestion(user: Pick<IUser, 'name' | 'ema

usernames.push(settings.get('Accounts_DefaultUsernamePrefixSuggestion'));

let index = await Users.col.countDocuments({ username: new RegExp(`^${usernames[0]}-[0-9]+`) });
let index = await Users.countDocuments({ username: new RegExp(`^${usernames[0]}-[0-9]+`) });
const username = '';
while (!username) {
// eslint-disable-next-line no-await-in-loop
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/business-hour/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const openBusinessHourDefault = async (): Promise<void> => {
};

export const createDefaultBusinessHourIfNotExists = async (): Promise<void> => {
if ((await LivechatBusinessHours.col.countDocuments({ type: LivechatBusinessHourTypes.DEFAULT })) === 0) {
if ((await LivechatBusinessHours.countDocuments({ type: LivechatBusinessHourTypes.DEFAULT })) === 0) {
await LivechatBusinessHours.insertOne(createDefaultBusinessHourRow());
}
};
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/push/server/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class PushClass {
// Add some verbosity about the send result, making sure the developer
// understands what just happened.
if (!countApn.length && !countGcm.length) {
if ((await AppsTokens.col.estimatedDocumentCount()) === 0) {
if ((await AppsTokens.estimatedDocumentCount()) === 0) {
logger.debug('GUIDE: The "AppsTokens" is empty - No clients have registered on the server yet...');
}
} else if (!countApn.length) {
Expand Down
34 changes: 17 additions & 17 deletions apps/meteor/app/statistics/server/lib/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ export const statistics = {
}

// User statistics
statistics.totalUsers = await Users.col.countDocuments({});
statistics.totalUsers = await Users.estimatedDocumentCount();
statistics.activeUsers = await Users.getActiveLocalUserCount();
statistics.activeGuests = await Users.getActiveLocalGuestCount();
statistics.nonActiveUsers = await Users.col.countDocuments({ active: false });
statistics.appUsers = await Users.col.countDocuments({ type: 'app' });
statistics.onlineUsers = await Users.col.countDocuments({ status: UserStatus.ONLINE });
statistics.awayUsers = await Users.col.countDocuments({ status: UserStatus.AWAY });
statistics.busyUsers = await Users.col.countDocuments({ status: UserStatus.BUSY });
statistics.nonActiveUsers = await Users.countDocuments({ active: false });
statistics.appUsers = await Users.countDocuments({ type: 'app' });
statistics.onlineUsers = await Users.countDocuments({ status: UserStatus.ONLINE });
statistics.awayUsers = await Users.countDocuments({ status: UserStatus.AWAY });
statistics.busyUsers = await Users.countDocuments({ status: UserStatus.BUSY });
statistics.totalConnectedUsers = statistics.onlineUsers + statistics.awayUsers;
statistics.offlineUsers = statistics.totalUsers - statistics.onlineUsers - statistics.awayUsers - statistics.busyUsers;
statsPms.push(
Expand All @@ -126,7 +126,7 @@ export const statistics = {
);

// Room statistics
statistics.totalRooms = await Rooms.col.countDocuments({});
statistics.totalRooms = await Rooms.estimatedDocumentCount();
statistics.totalChannels = await Rooms.countByType('c');
statistics.totalPrivateGroups = await Rooms.countByType('p');
statistics.totalDirect = await Rooms.countByType('d');
Expand Down Expand Up @@ -190,7 +190,7 @@ export const statistics = {
);

// Number of custom fields
statsPms.push((statistics.totalCustomFields = await LivechatCustomField.countDocuments({})));
statsPms.push((statistics.totalCustomFields = await LivechatCustomField.estimatedDocumentCount()));

// Number of public custom fields
statsPms.push((statistics.totalLivechatPublicCustomFields = await LivechatCustomField.countDocuments({ public: true })));
Expand Down Expand Up @@ -256,7 +256,7 @@ export const statistics = {

// Amount of VoIP Extensions connected
statsPms.push(
Users.col.countDocuments({ extension: { $exists: true } }).then((count) => {
Users.countDocuments({ extension: { $exists: true } }).then((count) => {
statistics.voipExtensions = count;
}),
);
Expand Down Expand Up @@ -313,25 +313,25 @@ export const statistics = {

// Message statistics
const channels = await Rooms.findByType('c', { projection: { msgs: 1, prid: 1 } }).toArray();
const totalChannelDiscussionsMessages = await channels.reduce(function _countChannelDiscussionsMessages(num: number, room: IRoom) {
const totalChannelDiscussionsMessages = channels.reduce(function _countChannelDiscussionsMessages(num: number, room: IRoom) {
return num + (room.prid ? room.msgs : 0);
}, 0);
statistics.totalChannelMessages =
(await channels.reduce(function _countChannelMessages(num: number, room: IRoom) {
channels.reduce(function _countChannelMessages(num: number, room: IRoom) {
return num + room.msgs;
}, 0)) - totalChannelDiscussionsMessages;
}, 0) - totalChannelDiscussionsMessages;

const privateGroups = await Rooms.findByType('p', { projection: { msgs: 1, prid: 1 } }).toArray();
const totalPrivateGroupsDiscussionsMessages = await privateGroups.reduce(function _countPrivateGroupsDiscussionsMessages(
const totalPrivateGroupsDiscussionsMessages = privateGroups.reduce(function _countPrivateGroupsDiscussionsMessages(
num: number,
room: IRoom,
) {
return num + (room.prid ? room.msgs : 0);
}, 0);
statistics.totalPrivateGroupMessages =
(await privateGroups.reduce(function _countPrivateGroupMessages(num: number, room: IRoom) {
privateGroups.reduce(function _countPrivateGroupMessages(num: number, room: IRoom) {
return num + room.msgs;
}, 0)) - totalPrivateGroupsDiscussionsMessages;
}, 0) - totalPrivateGroupsDiscussionsMessages;

statistics.totalDiscussionsMessages = totalPrivateGroupsDiscussionsMessages + totalChannelDiscussionsMessages;

Expand Down Expand Up @@ -394,7 +394,7 @@ export const statistics = {

statistics.enterpriseReady = true;
statsPms.push(
Uploads.col.estimatedDocumentCount().then((count) => {
Uploads.estimatedDocumentCount().then((count) => {
statistics.uploadsTotal = count;
}),
);
Expand All @@ -417,7 +417,7 @@ export const statistics = {

statistics.migration = await getControl();
statsPms.push(
InstanceStatus.col.countDocuments({ _updatedAt: { $gt: new Date(Date.now() - process.uptime() * 1000 - 2000) } }).then((count) => {
InstanceStatus.countDocuments({ _updatedAt: { $gt: new Date(Date.now() - process.uptime() * 1000 - 2000) } }).then((count) => {
statistics.instanceCount = count;
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defaultPriorities: Omit<ILivechatPriority, '_id' | '_updatedAt'>[] = [
];

export const createDefaultPriorities = async (): Promise<void> => {
const priorities = await LivechatPriority.col.countDocuments({});
const priorities = await LivechatPriority.estimatedDocumentCount();

if (!priorities) {
await LivechatPriority.insertMany(defaultPriorities);
Expand Down
14 changes: 7 additions & 7 deletions apps/meteor/ee/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ export class LivechatRoomsRawEE extends LivechatRoomsRaw implements ILivechatRoo
}

countPrioritizedRooms(): Promise<number> {
return this.col.countDocuments({ priorityId: { $exists: true } });
return this.countDocuments({ priorityId: { $exists: true } });
}

countRoomsWithSla(): Promise<number> {
return this.col.countDocuments({ slaId: { $exists: true } });
return this.countDocuments({ slaId: { $exists: true } });
}

countRoomsWithPdfTranscriptRequested(): Promise<number> {
return this.col.countDocuments({ pdfTranscriptRequested: true });
return this.countDocuments({ pdfTranscriptRequested: true });
}

countRoomsWithTranscriptSent(): Promise<number> {
return this.col.countDocuments({ pdfTranscriptFileId: { $exists: true } });
return this.countDocuments({ pdfTranscriptFileId: { $exists: true } });
}

async unsetAllPredictedVisitorAbandonment(): Promise<void> {
Expand Down Expand Up @@ -548,7 +548,7 @@ export class LivechatRoomsRawEE extends LivechatRoomsRaw implements ILivechatRoo
}

getTotalConversationsWithoutDepartmentBetweenDates(start: Date, end: Date, extraQuery: Filter<IOmnichannelRoom>): Promise<number> {
return this.col.countDocuments({
return this.countDocuments({
t: 'l',
departmentId: {
$exists: false,
Expand Down Expand Up @@ -626,7 +626,7 @@ export class LivechatRoomsRawEE extends LivechatRoomsRaw implements ILivechatRoo
}

getConversationsWithoutTagsBetweenDate(start: Date, end: Date, extraQuery: Filter<IOmnichannelRoom>): Promise<number> {
return this.col.countDocuments({
return this.countDocuments({
t: 'l',
ts: {
$gte: start,
Expand Down Expand Up @@ -721,7 +721,7 @@ export class LivechatRoomsRawEE extends LivechatRoomsRaw implements ILivechatRoo
}

getTotalConversationsWithoutAgentsBetweenDate(start: Date, end: Date, extraQuery: Filter<IOmnichannelRoom>): Promise<number> {
return this.col.countDocuments({
return this.countDocuments({
t: 'l',
ts: {
$gte: start,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/models/raw/LivechatUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ export class LivechatUnitRaw extends BaseRaw<IOmnichannelBusinessUnit> implement
}

countUnits(): Promise<number> {
return this.col.countDocuments({ type: 'u' });
return this.countDocuments({ type: 'u' });
}
}
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/deleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Meteor.methods<ServerMethods>({
});
}

const adminCount = await Users.col.countDocuments({ roles: 'admin' });
const adminCount = await Users.countDocuments({ roles: 'admin' });

const userIsAdmin = user.roles?.indexOf('admin') > -1;

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/getTotalChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Meteor.methods<ServerMethods>({
});
}

return Rooms.col.countDocuments({ t: 'c' });
return Rooms.countDocuments({ t: 'c' });
},
});
4 changes: 2 additions & 2 deletions packages/models/src/models/FreeSwitchCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class FreeSwitchCallRaw extends BaseRaw<IFreeSwitchCall> implements IFree
}

public countCallsByDirection(direction: IFreeSwitchCall['direction'], minDate?: Date, options?: CountDocumentsOptions): Promise<number> {
return this.col.countDocuments(
return this.countDocuments(
{
direction,
...(minDate && { startedAt: { $gte: minDate } }),
Expand Down Expand Up @@ -65,7 +65,7 @@ export class FreeSwitchCallRaw extends BaseRaw<IFreeSwitchCall> implements IFree
}

public countCallsBySuccessState(success: boolean, minDate?: Date, options?: CountDocumentsOptions): Promise<number> {
return this.col.countDocuments(
return this.countDocuments(
{
...(success ? { duration: { $gte: 5 } } : { $or: [{ duration: { $exists: false } }, { duration: { $lt: 5 } }] }),
...(minDate && { startedAt: { $gte: minDate } }),
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/models/ImportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ export class ImportDataRaw extends BaseRaw<IImportRecord> implements IImportData

async checkIfDirectMessagesExists(): Promise<boolean> {
return (
(await this.col.countDocuments({
(await this.countDocuments({
'dataType': 'channel',
'data.t': 'd',
})) > 0
);
}

async countMessages(): Promise<number> {
return this.col.countDocuments({ dataType: 'message' });
return this.countDocuments({ dataType: 'message' });
}

async findChannelImportIdByNameOrImportId(channelIdentifier: string): Promise<string | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/models/InstanceStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class InstanceStatusRaw extends BaseRaw<IInstanceStatus> implements IInst
}

async getActiveInstanceCount(): Promise<number> {
return this.col.countDocuments({ _updatedAt: { $gt: new Date(Date.now() - process.uptime() * 1000 - 2000) } });
return this.countDocuments({ _updatedAt: { $gt: new Date(Date.now() - process.uptime() * 1000 - 2000) } });
}

async getActiveInstancesAddress(): Promise<string[]> {
Expand Down
6 changes: 3 additions & 3 deletions packages/models/src/models/LivechatDepartment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class LivechatDepartmentRaw extends BaseRaw<ILivechatDepartment> implemen
}

countTotal(): Promise<number> {
return this.col.countDocuments();
return this.estimatedDocumentCount();
}

findInIds(departmentsIds: string[], options: FindOptions<ILivechatDepartment>): FindCursor<ILivechatDepartment> {
Expand Down Expand Up @@ -132,7 +132,7 @@ export class LivechatDepartmentRaw extends BaseRaw<ILivechatDepartment> implemen

countByBusinessHourIdExcludingDepartmentId(businessHourId: string, departmentId: string): Promise<number> {
const query = { businessHourId, _id: { $ne: departmentId } };
return this.col.countDocuments(query);
return this.countDocuments(query);
}

findEnabledByBusinessHourId(businessHourId: string, options: FindOptions<ILivechatDepartment>): FindCursor<ILivechatDepartment> {
Expand Down Expand Up @@ -453,7 +453,7 @@ export class LivechatDepartmentRaw extends BaseRaw<ILivechatDepartment> implemen
}

countArchived(): Promise<number> {
return this.col.countDocuments({ archived: true });
return this.countDocuments({ archived: true });
}

findByParentId(_parentId: string, _options?: FindOptions<ILivechatDepartment> | undefined): FindCursor<ILivechatDepartment> {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/models/LivechatDepartmentAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export class LivechatDepartmentAgentsRaw extends BaseRaw<ILivechatDepartmentAgen
}

countByDepartmentId(departmentId: string): Promise<number> {
return this.col.countDocuments({ departmentId });
return this.countDocuments({ departmentId });
}

disableAgentsByDepartmentId(departmentId: string): Promise<UpdateResult | Document> {
Expand Down
14 changes: 7 additions & 7 deletions packages/models/src/models/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
if (departmentId && departmentId !== 'undefined') {
query.departmentId = departmentId;
}
return this.col.countDocuments(query);
return this.countDocuments(query);
}

countAllClosedChatsBetweenDate({ start, end, departmentId }: { start: Date; end: Date; departmentId?: string }) {
Expand All @@ -741,7 +741,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
if (departmentId && departmentId !== 'undefined') {
query.departmentId = departmentId;
}
return this.col.countDocuments(query);
return this.countDocuments(query);
}

countAllQueuedChatsBetweenDate({ start, end, departmentId }: { start: Date; end: Date; departmentId?: string }) {
Expand All @@ -754,7 +754,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
if (departmentId && departmentId !== 'undefined') {
query.departmentId = departmentId;
}
return this.col.countDocuments(query);
return this.countDocuments(query);
}

countAllOpenChatsByAgentBetweenDate({ start, end, departmentId }: { start: Date; end: Date; departmentId?: string }) {
Expand Down Expand Up @@ -1357,7 +1357,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
query.departmentId = departmentId;
}

return this.col.countDocuments(query);
return this.countDocuments(query);
}

findAllServiceTimeByAgent({
Expand Down Expand Up @@ -2123,7 +2123,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
...(departmentId && departmentId !== 'undefined' && { departmentId }),
};

return this.col.countDocuments(query);
return this.countDocuments(query);
}

getAnalyticsMetricsBetweenDate(
Expand Down Expand Up @@ -2317,7 +2317,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
...extraQuery,
};

return this.col.countDocuments(query);
return this.countDocuments(query);
}

findOpenByAgent(userId: string, extraQuery: Filter<IOmnichannelRoom> = {}) {
Expand Down Expand Up @@ -2602,7 +2602,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
}

countLivechatRoomsWithDepartment(): Promise<number> {
return this.col.countDocuments({ departmentId: { $exists: true } });
return this.countDocuments({ departmentId: { $exists: true } });
}

async unsetAllPredictedVisitorAbandonment(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/models/MessageReads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export class MessageReadsRaw extends BaseRaw<MessageReads> implements IMessageRe
tmid,
userId: { $in: userIds },
};
return this.col.countDocuments(query);
return this.countDocuments(query);
}

async countByThreadId(tmid: IMessage['_id']): Promise<number> {
const query = {
tmid,
};
return this.col.countDocuments(query);
return this.countDocuments(query);
}
}
Loading
Loading