Skip to content

Commit

Permalink
Ensure DB queries in notifications service run in same transaction (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj authored Aug 19, 2024
1 parent 39f9515 commit e759f4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-comics-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@directus/api': patch
---

Fixed an issue where creating notifications could hang on SQLite
17 changes: 10 additions & 7 deletions api/src/services/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ const env = useEnv();
const logger = useLogger();

export class NotificationsService extends ItemsService {
usersService: UsersService;
mailService: MailService;

constructor(options: AbstractServiceOptions) {
super('directus_notifications', options);
this.usersService = new UsersService({ schema: this.schema });
this.mailService = new MailService({ schema: this.schema, accountability: this.accountability });
}

override async createOne(data: Partial<Notification>, opts?: MutationOptions): Promise<PrimaryKey> {
Expand All @@ -33,7 +28,9 @@ export class NotificationsService extends ItemsService {

async sendEmail(data: Partial<Notification>) {
if (data.recipient) {
const user = await this.usersService.readOne(data.recipient, {
const usersService = new UsersService({ schema: this.schema, knex: this.knex });

const user = await usersService.readOne(data.recipient, {
fields: ['id', 'email', 'email_notifications', 'role'],
});

Expand All @@ -54,7 +51,13 @@ export class NotificationsService extends ItemsService {
this.knex,
);

this.mailService
const mailService = new MailService({
schema: this.schema,
knex: this.knex,
accountability: this.accountability,
});

mailService
.send({
template: {
name: 'base',
Expand Down

0 comments on commit e759f4b

Please sign in to comment.