Skip to content

Commit

Permalink
Merge pull request #30359 from RocketChat/release-6.3.5
Browse files Browse the repository at this point in the history
Release 6.3.5
  • Loading branch information
sampaiodiego authored Sep 12, 2023
2 parents 6624799 + 0392340 commit 643bd6a
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 141 deletions.
5 changes: 5 additions & 0 deletions .changeset/bump-patch-1694524270831.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Bump @rocket.chat/meteor version.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-points-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fix a bug that prevented the error message from being shown in the private app installation page
5 changes: 5 additions & 0 deletions .changeset/slimy-cheetahs-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed selected departments not being displayed due to pagination
8 changes: 8 additions & 0 deletions .changeset/strong-laws-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rocket.chat/model-typings': patch
'@rocket.chat/meteor': patch
---

Change SAU aggregation to consider only sessions from few days ago instead of the whole past.

This is particularly important for large workspaces in case the cron job did not run for some time, in that case the amount of sessions would accumulate and the aggregation would take a long time to run.
38 changes: 12 additions & 26 deletions apps/meteor/app/statistics/server/lib/SAUMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,33 +318,19 @@ export class SAUMonitorClass {
return;
}

logger.info('[aggregate] - Aggregating data.');

const date = new Date();
date.setDate(date.getDate() - 0); // yesterday
const yesterday = getDateObj(date);

for await (const record of aggregates.dailySessionsOfYesterday(Sessions.col, yesterday)) {
await Sessions.updateOne(
{ _id: `${record.userId}-${record.year}-${record.month}-${record.day}` },
{ $set: record },
{ upsert: true },
);
const today = new Date();

// get sessions from 3 days ago to make sure even if a few cron jobs were skipped, we still have the data
const threeDaysAgo = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 3, 0, 0, 0, 0);

const period = { start: getDateObj(threeDaysAgo), end: getDateObj(today) };

logger.info({ msg: '[aggregate] - Aggregating data.', period });

for await (const record of aggregates.dailySessions(Sessions.col, period)) {
await Sessions.updateDailySessionById(`${record.userId}-${record.year}-${record.month}-${record.day}`, record);
}

await Sessions.updateMany(
{
type: 'session',
year: { $lte: yesterday.year },
month: { $lte: yesterday.month },
day: { $lte: yesterday.day },
},
{
$set: {
type: 'computed-session',
_computedAt: new Date(),
},
},
);
await Sessions.updateAllSessionsByDateToComputed(period);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type DepartmentListItem = {
_id: string;
label: string;
value: string;
_updatedAt: Date;
};

export const useDepartmentsList = (
Expand Down Expand Up @@ -66,7 +65,6 @@ export const useDepartmentsList = (
_id,
label: department.archived ? `${name} [${t('Archived')}]` : name,
value: _id,
_updatedAt: new Date(_updatedAt || ''),
};
});

Expand All @@ -75,15 +73,13 @@ export const useDepartmentsList = (
_id: '',
label: t('All'),
value: 'all',
_updatedAt: new Date(),
});

options.haveNone &&
items.unshift({
_id: '',
label: t('None'),
value: '',
_updatedAt: new Date(),
});

return {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/client/views/marketplace/AppInstallPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { useForm } from '../../hooks/useForm';
import AppPermissionsReviewModal from './AppPermissionsReviewModal';
import AppUpdateModal from './AppUpdateModal';
import AppInstallModal from './components/AppInstallModal/AppInstallModal';
import { handleAPIError, handleInstallError } from './helpers';
import { handleAPIError } from './helpers/handleAPIError';
import { handleInstallError } from './helpers/handleInstallError';
import { useAppsCountQuery } from './hooks/useAppsCountQuery';
import { getManifestFromZippedApp } from './lib/getManifestFromZippedApp';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const EditDepartmentWithData = ({ id, title }: EditDepartmentWithDataProps) => {
});

if (isInitialLoading) {
return <FormSkeleton />;
return <FormSkeleton padding='1.5rem 1rem' maxWidth='37.5rem' margin='0 auto' />;
}

if (isError || (id && !data?.department)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export const DepartmentForwarding = ({ departmentId, value = [], handler, label

const { phase: departmentsPhase, items: departmentsItems, itemCount: departmentsTotal } = useRecordList(departmentsList);

const options = useMemo(() => {
const pending = value.filter(({ value }) => !departmentsItems.find((dep) => dep.value === value));
return [...departmentsItems, ...pending];
}, [departmentsItems, value]);

return (
<Field>
<Field.Label>{t(label)}</Field.Label>
Expand All @@ -41,7 +46,7 @@ export const DepartmentForwarding = ({ departmentId, value = [], handler, label
filter={debouncedDepartmentsFilter}
setFilter={setDepartmentsFilter}
onChange={handler}
options={departmentsItems}
options={options}
value={value}
placeholder={t('Select_an_option')}
endReached={
Expand Down
205 changes: 105 additions & 100 deletions apps/meteor/server/models/raw/Sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ const getProjectionByFullDate = (): { day: string; month: string; year: string }
});

export const aggregates = {
dailySessionsOfYesterday(
dailySessions(
collection: Collection<ISession>,
{ year, month, day }: DestructuredDate,
{ start, end }: DestructuredRange,
): AggregationCursor<
Pick<ISession, 'mostImportantRole' | 'userId' | 'day' | 'year' | 'month' | 'type'> & {
time: number;
Expand All @@ -178,115 +178,101 @@ export const aggregates = {
_computedAt: string;
}
> {
return collection.aggregate<
Pick<ISession, 'mostImportantRole' | 'userId' | 'day' | 'year' | 'month' | 'type'> & {
time: number;
sessions: number;
devices: ISession['device'][];
_computedAt: string;
}
>(
[
{
$match: {
userId: { $exists: true },
lastActivityAt: { $exists: true },
device: { $exists: true },
type: 'session',
$or: [
{
year: { $lt: year },
},
{
year,
month: { $lt: month },
},
{
year,
month,
day: { $lte: day },
},
],
},
},
{
$project: {
userId: 1,
device: 1,
day: 1,
month: 1,
year: 1,
mostImportantRole: 1,
time: { $trunc: { $divide: [{ $subtract: ['$lastActivityAt', '$loginAt'] }, 1000] } },
},
},
{
$match: {
time: { $gt: 0 },
},
const pipeline = [
{
$match: {
userId: { $exists: true },
lastActivityAt: { $exists: true },
device: { $exists: true },
type: 'session',
...matchBasedOnDate(start, end),
},
{
$group: {
_id: {
userId: '$userId',
device: '$device',
day: '$day',
month: '$month',
year: '$year',
},
mostImportantRole: { $first: '$mostImportantRole' },
time: { $sum: '$time' },
sessions: { $sum: 1 },
},
},
{
$project: {
userId: 1,
device: 1,
day: 1,
month: 1,
year: 1,
mostImportantRole: 1,
time: { $trunc: { $divide: [{ $subtract: ['$lastActivityAt', '$loginAt'] }, 1000] } },
},
{
$sort: {
time: -1,
},
},
{
$match: {
time: { $gt: 0 },
},
{
$group: {
_id: {
userId: '$_id.userId',
day: '$_id.day',
month: '$_id.month',
year: '$_id.year',
},
mostImportantRole: { $first: '$mostImportantRole' },
time: { $sum: '$time' },
sessions: { $sum: '$sessions' },
devices: {
$push: {
sessions: '$sessions',
time: '$time',
device: '$_id.device',
},
},
},
{
$group: {
_id: {
userId: '$userId',
device: '$device',
day: '$day',
month: '$month',
year: '$year',
},
mostImportantRole: { $first: '$mostImportantRole' },
time: { $sum: '$time' },
sessions: { $sum: 1 },
},
{
$sort: {
_id: 1,
},
},
{
$sort: {
time: -1,
},
{
$project: {
_id: 0,
type: { $literal: 'user_daily' },
_computedAt: { $literal: new Date() },
},
{
$group: {
_id: {
userId: '$_id.userId',
day: '$_id.day',
month: '$_id.month',
year: '$_id.year',
userId: '$_id.userId',
mostImportantRole: 1,
time: 1,
sessions: 1,
devices: 1,
},
mostImportantRole: { $first: '$mostImportantRole' },
time: { $sum: '$time' },
sessions: { $sum: '$sessions' },
devices: {
$push: {
sessions: '$sessions',
time: '$time',
device: '$_id.device',
},
},
},
],
{ allowDiskUse: true },
);
},
{
$sort: {
_id: 1,
},
},
{
$project: {
_id: 0,
type: { $literal: 'user_daily' },
_computedAt: { $literal: new Date() },
day: '$_id.day',
month: '$_id.month',
year: '$_id.year',
userId: '$_id.userId',
mostImportantRole: 1,
time: 1,
sessions: 1,
devices: 1,
},
},
];

return collection.aggregate<
Pick<ISession, 'mostImportantRole' | 'userId' | 'day' | 'year' | 'month' | 'type'> & {
time: number;
sessions: number;
devices: ISession['device'][];
_computedAt: string;
}
>(pipeline, { allowDiskUse: true });
},

async getUniqueUsersOfYesterday(
Expand Down Expand Up @@ -1616,4 +1602,23 @@ export class SessionsRaw extends BaseRaw<ISession> implements ISessionsModel {

return this.col.bulkWrite(ops, { ordered: false });
}

async updateDailySessionById(_id: ISession['_id'], record: Partial<ISession>): Promise<UpdateResult> {
return this.updateOne({ _id }, { $set: record }, { upsert: true });
}

async updateAllSessionsByDateToComputed({ start, end }: DestructuredRange): Promise<UpdateResult | Document> {
return this.updateMany(
{
type: 'session',
...matchBasedOnDate(start, end),
},
{
$set: {
type: 'computed-session',
_computedAt: new Date(),
},
},
);
}
}
4 changes: 4 additions & 0 deletions packages/model-typings/src/models/ISessionsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,8 @@ export interface ISessionsModel extends IBaseModel<ISession> {
}): Promise<UpdateResult | Document>;

createBatch(sessions: OptionalId<ISession>[]): Promise<BulkWriteResult | undefined>;

updateDailySessionById(_id: ISession['_id'], record: Partial<ISession>): Promise<UpdateResult>;

updateAllSessionsByDateToComputed({ start, end }: DestructuredRange): Promise<UpdateResult | Document>;
}
Loading

0 comments on commit 643bd6a

Please sign in to comment.