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
5 changes: 5 additions & 0 deletions .changeset/empty-boxes-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes engagement dashboard loading unnecessary data into memory on startup
Comment thread
d-gubert marked this conversation as resolved.
6 changes: 3 additions & 3 deletions apps/meteor/ee/server/lib/engagementDashboard/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export const handleMessagesDeleted = async (message: IMessage, { room }: { room:
};

export const fillFirstDaysOfMessagesIfNeeded = async (date: Date): Promise<void> => {
const messagesFromAnalytics = await Analytics.findByTypeBeforeDate({
const messagesFromAnalytics = await Analytics.findOneByTypeBeforeDate({
type: 'messages',
date: convertDateToInt(date),
}).toArray();
Comment thread
KevLehman marked this conversation as resolved.
if (!messagesFromAnalytics.length) {
});
if (!messagesFromAnalytics) {
const startOfPeriod = moment(date).subtract(90, 'days').toDate();
const messages = await Messages.getTotalOfMessagesSentByDate({
start: startOfPeriod,
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/ee/server/lib/engagementDashboard/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const handleUserCreated = async (user: IUser): Promise<IUser> => {
};

export const fillFirstDaysOfUsersIfNeeded = async (date: Date): Promise<void> => {
const usersFromAnalytics = await Analytics.findByTypeBeforeDate({
const usersFromAnalytics = await Analytics.findOneByTypeBeforeDate({
type: 'users',
date: convertDateToInt(date),
}).toArray();
if (!usersFromAnalytics.length) {
});
if (!usersFromAnalytics) {
const startOfPeriod = moment(date).subtract(90, 'days').toDate();
const users = await Users.getTotalOfRegisteredUsersByDate({
start: startOfPeriod,
Expand Down
4 changes: 2 additions & 2 deletions packages/model-typings/src/models/IAnalyticsModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IAnalytics, IRoom } from '@rocket.chat/core-typings';
import type { AggregationCursor, FindCursor, FindOptions, UpdateResult, Document } from 'mongodb';
import type { AggregationCursor, FindOptions, UpdateResult, Document } from 'mongodb';

import type { IBaseModel } from './IBaseModel';
import type { IChannelsWithNumberOfMessagesBetweenDate } from './IRoomsModel';
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface IAnalyticsModel extends IBaseModel<IAnalytics> {
_id: IAnalytics['date'];
users: number;
}>;
findByTypeBeforeDate({ type, date }: { type: IAnalytics['type']; date: IAnalytics['date'] }): FindCursor<IAnalytics>;
findOneByTypeBeforeDate({ type, date }: { type: IAnalytics['type']; date: IAnalytics['date'] }): Promise<IAnalytics | null>;
findRoomsByTypesWithNumberOfMessagesBetweenDate(params: {
types: Array<IRoom['t']>;
start: number;
Expand Down
6 changes: 3 additions & 3 deletions packages/models/src/models/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IAnalytics, IRoom } from '@rocket.chat/core-typings';
import type { IAnalyticsModel, IChannelsWithNumberOfMessagesBetweenDate } from '@rocket.chat/model-typings';
import { Random } from '@rocket.chat/random';
import type { AggregationCursor, FindCursor, Db, IndexDescription, FindOptions, UpdateResult, Document, Collection } from 'mongodb';
import type { AggregationCursor, Db, IndexDescription, FindOptions, UpdateResult, Document, Collection } from 'mongodb';

import { BaseRaw } from './BaseRaw';
import { readSecondaryPreferred } from '../readSecondaryPreferred';
Expand Down Expand Up @@ -212,8 +212,8 @@ export class AnalyticsRaw extends BaseRaw<IAnalytics> implements IAnalyticsModel
);
}

findByTypeBeforeDate({ type, date }: { type: IAnalytics['type']; date: IAnalytics['date'] }): FindCursor<IAnalytics> {
return this.find({ type, date: { $lte: date } });
findOneByTypeBeforeDate({ type, date }: { type: IAnalytics['type']; date: IAnalytics['date'] }): Promise<IAnalytics | null> {
return this.findOne({ type, date: { $lte: date } });
}

getRoomsWithNumberOfMessagesBetweenDateQuery({
Expand Down
Loading