Skip to content

Commit f220525

Browse files
Update prod (#552)
* feat(metrics): expose worker metrics over HTTP (#547) * perf(notifier): project only notifications field when loading rules (#551) * perf(notifier): project only notifications field when loading rules * test(notifier): update findOne assertion for projection arg --------- Co-authored-by: Kuchizu <70284260+Kuchizu@users.noreply.github.com>
1 parent 2d4904c commit f220525

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

workers/notifier/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,12 @@ export default class NotifierWorker extends Worker {
193193
*/
194194
private async getProjectNotificationRules(projectId: string): Promise<Rule[]> {
195195
const connection = this.accountsDb.getConnection();
196-
const projects = connection.collection('projects');
196+
const projects = connection.collection<{ notifications?: Rule[] }>('projects');
197197

198-
const project = await projects.findOne({ _id: new ObjectID(projectId) });
198+
const project = await projects.findOne(
199+
{ _id: new ObjectID(projectId) },
200+
{ projection: { notifications: 1 } }
201+
);
199202

200203
if (!project) {
201204
throw new Error('There is no project with given id');

workers/notifier/tests/worker.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ describe('NotifierWorker', () => {
242242

243243
await worker.handle(message);
244244

245-
expect(dbQueryMock).toBeCalledWith({ _id: new ObjectID(message.projectId) });
245+
expect(dbQueryMock).toBeCalledWith(
246+
{ _id: new ObjectID(message.projectId) },
247+
{ projection: { notifications: 1 } }
248+
);
246249
});
247250

248251
it('should close db connection on finish', async () => {

0 commit comments

Comments
 (0)