Skip to content

Commit

Permalink
Fix Notification mail race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Agreon committed Sep 16, 2023
1 parent 287b7ee commit 12598ba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/components/InfoSource/InfoSourceOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const InfoSourceOptions: React.FC = () => {

<AlertDialogBody>
Do you not want to be bothered again or should we keep searching
for alternatives?
for alternatives with search term {"'"}{game.search}{"'"}?
</AlertDialogBody>

<AlertDialogFooter display="flex" justifyContent="space-between">
Expand Down
9 changes: 4 additions & 5 deletions notifier/src/mail-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ export class MailService {
const game = notification.game.getEntity();
const infoSource = notification.infoSource.getEntity();

const gameName = game.name || game.search;
// We rather display the resolved name so a user can see instantly if an unrelated
// game was added.
const infoSourceName = infoSource.data.fullName;

switch (notification.type) {
case NotificationType.GameReleased:
return `${gameName} will be available today in the ${infoSource.type} store`;
return `${infoSourceName} will be available today in the ${infoSource.type} store`;
case NotificationType.GameReduced:
return `${gameName} was reduced in the ${infoSource.type} store`;
return `${infoSourceName} was reduced in the ${infoSource.type} store`;
case NotificationType.ReleaseDateChanged:
return `The release date of ${gameName} changed`;
return `The release date of ${infoSourceName} changed`;
case NotificationType.NewStoreEntry:
return `${infoSourceName} was added to the ${infoSource.type} store`;
case NotificationType.NewMetacriticRating:
Expand All @@ -56,7 +55,7 @@ export class MailService {
case NotificationType.LeftEarlyAccess:
return `${infoSourceName} left Early Access`;
case NotificationType.ResolveError:
return `${gameName} could not be resolved`;
return `${game.name || game.search} could not be resolved`;
}
}

Expand Down
4 changes: 4 additions & 0 deletions notifier/src/notification-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class NotificationService {
{ populate: ['game', 'user'] }
);
const game = infoSource.game.getEntity();
if (!game.setupCompleted) {
return;
}

const user = infoSource.user.getEntity();

const logger = this.sourceScopedLogger.child({
Expand Down
12 changes: 6 additions & 6 deletions resolver/src/resolve-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export class ResolveService {

logger.debug(`Resolved source information in ${source.type}`);

await this.em.nativeUpdate(InfoSource, sourceId, {
state: InfoSourceState.Resolved,
data: resolvedGameData,
updatedAt: new Date()
});

if (!triggeredManually) {
await this.addToNotificationQueue({
sourceId,
Expand All @@ -79,12 +85,6 @@ export class ResolveService {
});
}

await this.em.nativeUpdate(InfoSource, sourceId, {
state: InfoSourceState.Resolved,
data: resolvedGameData,
updatedAt: new Date()
});

// Delete old, unnecessary ResolveError notifications so that on a new error a
// new notification is created.
await this.em.nativeDelete(Notification, {
Expand Down

0 comments on commit 12598ba

Please sign in to comment.