Skip to content

Commit

Permalink
move DatabaseWatcher to models package
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Dec 27, 2024
1 parent 9071dbf commit 8475de5
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/server/modules/watchers/watchers.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import {
Permissions,
LivechatPriority,
} from '@rocket.chat/models';
import type { DatabaseWatcher } from '@rocket.chat/models';

import { getMessageToBroadcast } from '../../../app/lib/server/lib/notifyListener';
import { subscriptionFields, roomFields } from '../../../lib/publishFields';
import type { DatabaseWatcher } from '../../database/DatabaseWatcher';

type BroadcastCallback = <T extends keyof EventSignatures>(event: T, ...args: Parameters<EventSignatures[T]>) => Promise<void>;

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/startup/watchDb.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { api, dbWatchersDisabled } from '@rocket.chat/core-services';
import { Logger } from '@rocket.chat/logger';
import { DatabaseWatcher } from '@rocket.chat/models';
import { MongoInternals } from 'meteor/mongo';

import { metrics } from '../../app/metrics/server/lib/metrics';
import { DatabaseWatcher } from '../database/DatabaseWatcher';
import { db } from '../database/utils';
import { SystemLogger } from '../lib/logger/system';
import { initWatchers } from '../modules/watchers/watchers.module';
Expand Down
2 changes: 1 addition & 1 deletion ee/apps/stream-hub-service/src/StreamHub.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IServiceClass } from '@rocket.chat/core-services';
import { ServiceClass } from '@rocket.chat/core-services';
import type { Logger } from '@rocket.chat/logger';
import type { DatabaseWatcher } from '@rocket.chat/models';

import type { DatabaseWatcher } from '../../../../apps/meteor/server/database/DatabaseWatcher';
import { initWatchers } from '../../../../apps/meteor/server/modules/watchers/watchers.module';

export class StreamHub extends ServiceClass implements IServiceClass {
Expand Down
3 changes: 1 addition & 2 deletions ee/apps/stream-hub-service/src/service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { api, getConnection, getTrashCollection } from '@rocket.chat/core-services';
import { Logger } from '@rocket.chat/logger';
import { registerServiceModels } from '@rocket.chat/models';
import { DatabaseWatcher, registerServiceModels } from '@rocket.chat/models';
import { broker } from '@rocket.chat/network-broker';
import { startTracing } from '@rocket.chat/tracing';
import polka from 'polka';

import { StreamHub } from './StreamHub';
import { DatabaseWatcher } from '../../../../apps/meteor/server/database/DatabaseWatcher';

const PORT = process.env.PORT || 3035;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export class DatabaseWatcher extends EventEmitter {
/**
* Last doc timestamp received from a real time event
*/
private lastDocTS: Date;
private lastDocTS: Date | undefined;

private watchCollections: string[];
private watchCollections: string[] | undefined;

// eslint-disable-next-line @typescript-eslint/naming-convention
constructor({ db, _oplogHandle, metrics, logger: LoggerClass }: { db: Db; _oplogHandle?: any; metrics?: any; logger: typeof Logger }) {
Expand Down Expand Up @@ -127,7 +127,7 @@ export class DatabaseWatcher extends EventEmitter {
const stream = cursor.stream();

stream.on('data', (doc) => {
const doesMatter = this.watchCollections.some((collection) => doc.ns === `${dbName}.${collection}`);
const doesMatter = this.watchCollections?.some((collection) => doc.ns === `${dbName}.${collection}`);
if (!doesMatter) {
return;
}
Expand All @@ -149,7 +149,7 @@ export class DatabaseWatcher extends EventEmitter {

this.logger.startup('Using Meteor oplog');

this.watchCollections.forEach((collection) => {
this.watchCollections?.forEach((collection) => {
this._oplogHandle.onOplogEntry({ collection }, (event: any) => {
this.emitDoc(collection, convertOplogPayload(event));
});
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/models/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function getCollectionName(name: string): string {
}

export * from './modelClasses';
export * from './DatabaseWatcher';

export * from './dummy/ReadReceipts';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dbWatchersDisabled } from '@rocket.chat/core-services';

import {
Messages,
Users,
Expand All @@ -16,7 +17,7 @@ import {
PbxEvents,
Permissions,
LivechatPriority,
} from '@rocket.chat/models';
} from './index';

const { DBWATCHER_EXCLUDE_COLLECTIONS = '', DBWATCHER_ONLY_COLLECTIONS = '' } = process.env;

Expand Down

0 comments on commit 8475de5

Please sign in to comment.