Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into refa…
Browse files Browse the repository at this point in the history
…ctor/locationModal

* 'develop' of github.com:RocketChat/Rocket.Chat:
  i18n: Makes the text less ambiguous (#20895)
  Chore: Missing some English translation keywords (#20131)
  Chore: Exclude private/public folders from typecheck (#26399)
  [NEW] Marketplace apps page new list view layout (#26181)
  Chore: Rewrite custom OAuth Modals to react (#26204)
  i18n: Manual sync from LingoHub (#26397)
  Chore: Options in BaseRaw model could possibly be undefined (#26395)
  [IMPROVE] Use single change stream to watch DB changes (#26336)
  [IMPROVE] Remove public and node_modules folders from TypeScript server watcher (#26391)
  • Loading branch information
gabriellsh committed Jul 29, 2022
2 parents 0d124e3 + b11bab5 commit 58fbf59
Show file tree
Hide file tree
Showing 108 changed files with 2,744 additions and 2,336 deletions.
3 changes: 2 additions & 1 deletion apps/meteor/app/apps/client/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ class AppClientOrchestrator {
}

return (result as App[]).map((app: App) => {
const { latest, price, pricingPlans, purchaseType, isEnterpriseOnly, modifiedAt } = app;
const { latest, price, pricingPlans, purchaseType, isEnterpriseOnly, modifiedAt, bundledIn } = app;
return {
...latest,
price,
pricingPlans,
purchaseType,
isEnterpriseOnly,
modifiedAt,
bundledIn,
};
});
}
Expand Down
7 changes: 5 additions & 2 deletions apps/meteor/app/metrics/server/lib/collectMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import connect from 'connect';
import _ from 'underscore';
import gcStats from 'prometheus-gc-stats';
import { Meteor } from 'meteor/meteor';
import { MongoInternals } from 'meteor/mongo';
import { Facts } from 'meteor/facts-base';
import { Statistics } from '@rocket.chat/models';

import { Info, getOplogInfo } from '../../../utils/server';
import { Info } from '../../../utils/server';
import { getControl } from '../../../../server/lib/migrations';
import { settings } from '../../../settings/server';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { metrics } from './metrics';
import { getAppsStatistics } from '../../../statistics/server/lib/getAppsStatistics';

const { mongo } = MongoInternals.defaultRemoteCollectionDriver();

Facts.incrementServerFact = function (pkg: 'pkg' | 'fact', fact: string | number, increment: number): void {
metrics.meteorFacts.inc({ pkg, fact }, increment);
};
Expand Down Expand Up @@ -42,7 +45,7 @@ const setPrometheusData = async (): Promise<void> => {
metrics.totalAppsEnabled.set(totalActive || 0);
metrics.totalAppsFailed.set(totalFailed || 0);

const oplogQueue = getOplogInfo().mongo._oplogHandle?._entryQueue?.length || 0;
const oplogQueue = (mongo as any)._oplogHandle?._entryQueue?.length || 0;
metrics.oplogQueue.set(oplogQueue);

const statistics = await Statistics.findLast();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ if (Meteor.isClient) {
module.exports = require('./client/index.js');
}
if (Meteor.isServer) {
module.exports = require('./server/index.js');
module.exports = require('./server/index');
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import LivechatDepartmentAgents from './models/LivechatDepartmentAgents';
import LivechatRooms from './models/LivechatRooms';
import LivechatInquiry from './models/LivechatInquiry';
import ImportData from './models/ImportData';
import './lib/watchModels';

export { AppsLogsModel } from './models/apps-logs-model';
export { AppsPersistenceModel } from './models/apps-persistence-model';
Expand Down
73 changes: 0 additions & 73 deletions apps/meteor/app/models/server/lib/watchModels.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/meteor/app/models/server/models/_Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export class Base {
this.collectionName = this._db.collectionName;
this.name = this._db.name;

this.removeListener = this._db.removeListener.bind(this._db);
this.on = this._db.on.bind(this._db);
this.emit = this._db.emit.bind(this._db);

this.db = this;
}

Expand Down
130 changes: 1 addition & 129 deletions apps/meteor/app/models/server/models/_BaseDb.js
Original file line number Diff line number Diff line change
@@ -1,144 +1,16 @@
import { EventEmitter } from 'events';

import { Match } from 'meteor/check';
import { Mongo } from 'meteor/mongo';
import _ from 'underscore';

import { setUpdatedAt } from '../lib/setUpdatedAt';
import { metrics } from '../../../metrics/server/lib/metrics';
import { getOplogHandle } from './_oplogHandle';
import { isRunningMs } from '../../../../server/lib/isRunningMs';
import { trash } from '../../../../server/database/trash';

const baseName = 'rocketchat_';

const actions = {
i: 'insert',
u: 'update',
d: 'remove',
};

export class BaseDbWatch extends EventEmitter {
constructor(collectionName) {
super();
this.collectionName = collectionName;

if (!isRunningMs()) {
this.initDbWatch();
}
}

initDbWatch() {
const _oplogHandle = Promise.await(getOplogHandle());

// When someone start listening for changes we start oplog if available
const handleListener = async (event /* , listener*/) => {
if (event !== 'change') {
return;
}

this.removeListener('newListener', handleListener);

const query = {
collection: this.collectionName,
};

if (!_oplogHandle) {
throw new Error(`Error: Unable to find Mongodb Oplog. You must run the server with oplog enabled. Try the following:\n
1. Start your mongodb in a replicaset mode: mongod --smallfiles --oplogSize 128 --replSet rs0\n
2. Start the replicaset via mongodb shell: mongo mongo/meteor --eval "rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})"\n
3. Start your instance with OPLOG configuration: export MONGO_OPLOG_URL=mongodb://localhost:27017/local MONGO_URL=mongodb://localhost:27017/meteor node main.js
`);
}

_oplogHandle.onOplogEntry(query, this.processOplogRecord.bind(this));
// Meteor will handle if we have a value https://github.com/meteor/meteor/blob/5dcd0b2eb9c8bf881ffbee98bc4cb7631772c4da/packages/mongo/oplog_tailing.js#L5
if (process.env.METEOR_OPLOG_TOO_FAR_BEHIND == null) {
_oplogHandle._defineTooFarBehind(Number.MAX_SAFE_INTEGER);
}
};

if (_oplogHandle) {
this.on('newListener', handleListener);
}
}

processOplogRecord({ id, op }) {
const action = actions[op.op];
metrics.oplog.inc({
collection: this.collectionName,
op: action,
});

if (action === 'insert') {
this.emit('change', {
action,
clientAction: 'inserted',
id: op.o._id,
data: op.o,
oplog: true,
});
return;
}

if (action === 'update') {
if (!op.o.$set && !op.o.$unset) {
this.emit('change', {
action,
clientAction: 'updated',
id,
data: op.o,
oplog: true,
});
return;
}

const diff = {};
if (op.o.$set) {
for (const key in op.o.$set) {
if (op.o.$set.hasOwnProperty(key)) {
diff[key] = op.o.$set[key];
}
}
}
const unset = {};
if (op.o.$unset) {
for (const key in op.o.$unset) {
if (op.o.$unset.hasOwnProperty(key)) {
diff[key] = undefined;
unset[key] = 1;
}
}
}

this.emit('change', {
action,
clientAction: 'updated',
id,
diff,
unset,
oplog: true,
});
return;
}

if (action === 'remove') {
this.emit('change', {
action,
clientAction: 'removed',
id,
oplog: true,
});
}
}
}

export class BaseDb extends BaseDbWatch {
export class BaseDb {
constructor(model, baseModel, options = {}) {
const collectionName = Match.test(model, String) ? baseName + model : model._name;

super(collectionName);

this.collectionName = collectionName;

if (Match.test(model, String)) {
Expand Down
Loading

0 comments on commit 58fbf59

Please sign in to comment.