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

[NEW] New stats rewrite #25078

Merged
merged 24 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bce51c2
new stats
ostjen Apr 4, 2022
22eb83b
Merge branch 'develop' into newStatsRewrite
ostjen Apr 4, 2022
8c899b6
new stats
ostjen Apr 4, 2022
c214002
added roomswith pinned/starred
ostjen Apr 6, 2022
e0584dd
added whitelabel stats
ostjen Apr 6, 2022
5a052ec
Merge branch 'develop' into newStatsRewrite
ostjen Apr 6, 2022
e862118
Develop sync
matheusbsilva137 Apr 29, 2022
8ca868d
Add missing engagement metrics - phase 1
matheusbsilva137 May 5, 2022
36f9735
Fix typecheck errors
matheusbsilva137 May 6, 2022
5868830
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
matheusbsilva137 May 6, 2022
1d13999
fix stories files (add new stats properties)
matheusbsilva137 May 7, 2022
74653af
Use incrementValueById method
matheusbsilva137 May 7, 2022
1aaff29
Use statistics.telemetry endpoint to increment the Manual_Entry_User_…
matheusbsilva137 May 7, 2022
c46e588
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
matheusbsilva137 May 17, 2022
db6326e
Fix Settings import
matheusbsilva137 May 17, 2022
585047b
Merge remote-tracking branch 'origin/develop' into newStatsRewrite
sampaiodiego May 19, 2022
2022ae8
Fix Teams stats
sampaiodiego May 19, 2022
66a1626
Improve importer stats
sampaiodiego May 19, 2022
817e6f1
Remove not used method
sampaiodiego May 19, 2022
4f79dbd
Remove some stats
sampaiodiego May 19, 2022
a960449
Improve room find
sampaiodiego May 19, 2022
4869ffa
Add missing indexes
sampaiodiego May 19, 2022
3589a32
Run finds on secondaries
sampaiodiego May 19, 2022
5b536a4
Use index for starred queries
sampaiodiego May 19, 2022
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: 3 additions & 2 deletions apps/meteor/app/importer-csv/server/importer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Random } from 'meteor/random';

import { Base, ProgressStep, ImporterWebsocket } from '../../importer/server';
import { Users } from '../../models/server';
import { Users, Settings as SettingsRaw } from '../../models/server';

export class CsvImporter extends Base {
constructor(info, importRecord) {
Expand Down Expand Up @@ -119,7 +119,8 @@ export class CsvImporter extends Base {
});
}

super.updateRecord({ 'count.users': parsedUsers.length });
SettingsRaw.incrementValueById('CSV_Importer_Count', usersCount);
super.updateRecord({ 'count.users': usersCount });
return increaseProgressCount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from 'fs';
import { Meteor } from 'meteor/meteor';

import { Base, ProgressStep } from '../../importer/server';
import { Settings as SettingsRaw } from '../../models/server';

export class HipChatEnterpriseImporter extends Base {
constructor(info, importRecord) {
Expand Down Expand Up @@ -52,6 +53,7 @@ export class HipChatEnterpriseImporter extends Base {
this.converter.addUser(newUser);
}

SettingsRaw.incrementValueById('Hipchat_Enterprise_Importer_Count', count);
super.updateRecord({ 'count.users': count });
super.addCountToTotal(count);
}
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/app/importer-slack-users/server/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Random } from 'meteor/random';
import { RawImports, Base, ProgressStep, Selection, SelectionUser } from '../../importer/server';
import { RocketChatFile } from '../../file';
import { Users } from '../../models';
import { Settings as SettingsRaw } from '../../models/server';

export class SlackUsersImporter extends Base {
constructor(info, importRecord) {
Expand Down Expand Up @@ -164,6 +165,7 @@ export class SlackUsersImporter extends Base {
});
}

SettingsRaw.incrementValueById('Slack_Users_Importer_Count', this.users.users.length);
super.updateProgress(ProgressStep.FINISHING);
super.updateProgress(ProgressStep.DONE);
} catch (e) {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/importer-slack/server/importer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'underscore';

import { Base, ProgressStep, ImporterWebsocket } from '../../importer/server';
import { Messages, ImportData } from '../../models/server';
import { Messages, ImportData, Settings as SettingsRaw } from '../../models/server';
import { settings } from '../../settings/server';
import { MentionsParser } from '../../mentions/lib/MentionsParser';
import { getUserAvatarURL } from '../../utils/lib/getUserAvatarURL';
Expand Down Expand Up @@ -155,6 +155,7 @@ export class SlackImporter extends Base {
}

this.converter.addUser(newUser);
SettingsRaw.incrementValueById('Slack_Importer_Count');
}
}

Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/app/lib/server/methods/sendInvitationEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { check } from 'meteor/check';
import * as Mailer from '../../../mailer';
import { hasPermission } from '../../../authorization';
import { settings } from '../../../settings';
import { Settings as SettingsRaw } from '../../../models/server';

let html = '';
Meteor.startup(() => {
Expand Down Expand Up @@ -37,7 +38,7 @@ Meteor.methods({

return validEmails.filter((email) => {
try {
return Mailer.send({
const mailerResult = Mailer.send({
to: email,
from: settings.get('From_Email'),
subject,
Expand All @@ -46,6 +47,9 @@ Meteor.methods({
email,
},
});

SettingsRaw.incrementValueById('Invitation_Email_Count');
return mailerResult;
} catch ({ message }) {
throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${message}`, {
method: 'sendInvitationEmail',
Expand Down
5 changes: 5 additions & 0 deletions apps/meteor/app/lib/server/startup/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ settingsRegistry.addGroup('Email', function () {
);
});

this.add('Invitation_Email_Count', 0, {
type: 'int',
hidden: true,
});

this.section('Forgot_password_section', function () {
this.add('Forgot_Password_Email_Subject', '{Forgot_Password_Email_Subject}', {
type: 'string',
Expand Down
20 changes: 20 additions & 0 deletions apps/meteor/app/lib/server/startup/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ settingsRegistry.addGroup('Accounts', function () {
type: 'string',
hidden: true,
});
this.add('Manual_Entry_User_Count', 0, {
type: 'int',
hidden: true,
});
this.add('CSV_Importer_Count', 0, {
type: 'int',
hidden: true,
});
this.add('Hipchat_Enterprise_Importer_Count', 0, {
type: 'int',
hidden: true,
});
this.add('Slack_Importer_Count', 0, {
type: 'int',
hidden: true,
});
this.add('Slack_Users_Importer_Count', 0, {
type: 'int',
hidden: true,
});
this.add('Accounts_UseDefaultBlockedDomainsList', true, {
type: 'boolean',
});
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/models/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Rooms extends Base {
// field used for DMs only
this.tryEnsureIndex({ uids: 1 }, { sparse: true });
this.tryEnsureIndex({ createdOTR: 1 }, { sparse: true });
this.tryEnsureIndex({ encrypted: 1 }, { sparse: true }); // used on statistics

this.tryEnsureIndex(
{
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/models/server/models/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ export class Settings extends Base {
return this.update(query, update);
}

incrementValueById(_id) {
incrementValueById(_id, value = 1) {
const query = {
blocked: { $ne: true },
_id,
};

const update = {
$inc: {
value: 1,
value,
},
};

Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class Users extends Base {
this.tryEnsureIndex({ extension: 1 }, { sparse: true, unique: true });
this.tryEnsureIndex({ language: 1 }, { sparse: true });

this.tryEnsureIndex({ 'active': 1, 'services.email2fa.enabled': 1 }, { sparse: true }); // used by statistics
this.tryEnsureIndex({ 'active': 1, 'services.totp.enabled': 1 }, { sparse: true }); // used by statistics

const collectionObj = this.model.rawCollection();
this.findAndModify = Meteor.wrapAsync(collectionObj.findAndModify, collectionObj);
}
Expand Down
8 changes: 8 additions & 0 deletions apps/meteor/app/models/server/raw/Invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ export class InvitesRaw extends BaseRaw<T> {
},
);
}

async countUses(): Promise<number> {
const [result] = await this.col
.aggregate<{ totalUses: number } | undefined>([{ $group: { _id: null, totalUses: { $sum: '$uses' } } }])
.toArray();

return result?.totalUses || 0;
}
}
42 changes: 42 additions & 0 deletions apps/meteor/app/models/server/raw/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,46 @@ export class MessagesRaw extends BaseRaw {
options,
);
}

async countRoomsWithStarredMessages(options) {
const [queryResult] = await this.col
.aggregate(
[{ $match: { 'starred._id': { $exists: true } } }, { $group: { _id: '$rid' } }, { $group: { _id: null, total: { $sum: 1 } } }],
options,
)
.toArray();

return queryResult?.total || 0;
}

async countRoomsWithPinnedMessages(options) {
const [queryResult] = await this.col
.aggregate([{ $match: { pinned: true } }, { $group: { _id: '$rid' } }, { $group: { _id: null, total: { $sum: 1 } } }], options)
.toArray();

return queryResult?.total || 0;
}

async countE2EEMessages(options) {
return this.find({ t: 'e2e' }, options).count();
}

findPinned(options) {
const query = {
t: { $ne: 'rm' },
_hidden: { $ne: true },
pinned: true,
};

return this.find(query, options);
}

findStarred(options) {
const query = {
'_hidden': { $ne: true },
'starred._id': { $exists: true },
};

return this.find(query, options);
}
}
17 changes: 17 additions & 0 deletions apps/meteor/app/models/server/raw/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,21 @@ export class RoomsRaw extends BaseRaw {
},
]);
}

findByE2E(options) {
return this.find(
{
encrypted: true,
},
options,
);
}

findRoomsInsideTeams(autoJoin = false) {
return this.find({
teamId: { $exists: true },
teamMain: { $exists: false },
...(autoJoin && { teamDefault: true }),
});
}
}
16 changes: 16 additions & 0 deletions apps/meteor/app/models/server/raw/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,4 +999,20 @@ export class UsersRaw extends BaseRaw {

return this.find(query, options);
}

findActiveUsersTOTPEnable(options) {
const query = {
'active': true,
'services.totp.enabled': true,
sampaiodiego marked this conversation as resolved.
Show resolved Hide resolved
};
return this.find(query, options);
}

findActiveUsersEmail2faEnable(options) {
const query = {
'active': true,
'services.email2fa.enabled': true,
sampaiodiego marked this conversation as resolved.
Show resolved Hide resolved
};
return this.find(query, options);
}
}
10 changes: 10 additions & 0 deletions apps/meteor/app/statistics/server/lib/getImporterStatistics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { settings } from '../../../settings/server';

export function getImporterStatistics(): Record<string, unknown> {
return {
totalCSVImportedUsers: settings.get('CSV_Importer_Count'),
totalHipchatEnterpriseImportedUsers: settings.get('Hipchat_Enterprise_Importer_Count'),
totalSlackImportedUsers: settings.get('Slack_Importer_Count'),
totalSlackUsersImportedUsers: settings.get('Slack_Users_Importer_Count'),
};
}
Loading