Skip to content

Commit

Permalink
- avoids grouping notifications with wrong categories
Browse files Browse the repository at this point in the history
- fixes for missing sourceTypes in statistics controller
  • Loading branch information
Lamarcke committed Dec 6, 2024
1 parent aca51ee commit 413a21c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/notifications/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,20 @@ export class NotificationsService {
comparedNotification.category,
);

const comparableProperties: (keyof Notification)[] = [
const comparableSourceIds: (keyof Notification)[] = [
"reviewId",
"activityId",
"reviewCommentId",
"activityCommentId",
];

const isSameSource = comparableProperties.some(
const hasSameCategory =
notification.category === comparedNotification.category;
const hasSameSourceType =
notification.sourceType ===
comparedNotification.sourceType;

const hasSameSourceId = comparableSourceIds.some(
(property) => {
return (
comparedNotification[property] != undefined &&
Expand All @@ -131,7 +137,11 @@ export class NotificationsService {
);

const isSimilar =
!isAlreadyProcessed && hasValidCategory && isSameSource;
!isAlreadyProcessed &&
hasValidCategory &&
hasSameCategory &&
hasSameSourceType &&
hasSameSourceId;

if (isSimilar) {
processedEntities.set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { StatisticsService } from "../statistics.types";
import { CommentStatisticsService } from "../comment-statistics.service";

@Processor(STATISTICS_QUEUE_NAME, {
concurrency: 300,
concurrency: 5,
})
export class StatisticsQueueProcessor extends WorkerHostProcessor {
logger = new Logger(StatisticsQueueProcessor.name);
Expand Down
12 changes: 11 additions & 1 deletion src/statistics/statistics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ export class StatisticsController {
return this.activityStatisticsService.findOne(
dto.sourceId as string,
);
case StatisticsSourceType.ACTIVITY_COMMENT:
return this.commentStatisticsService.findOne(
dto.sourceId as string,
StatisticsSourceType.ACTIVITY_COMMENT,
);
case StatisticsSourceType.REVIEW_COMMENT:
return this.commentStatisticsService.findOne(
dto.sourceId as string,
dto.sourceType,
StatisticsSourceType.REVIEW_COMMENT,
);
default:
throw new HttpException(
Expand Down Expand Up @@ -149,6 +154,11 @@ export class StatisticsController {
dto.statisticsId,
session?.getUserId(),
);
case StatisticsSourceType.ACTIVITY_COMMENT:
return this.commentStatisticsService.getStatus(
dto.statisticsId,
session?.getUserId(),
);
case StatisticsSourceType.REVIEW_COMMENT:
return this.commentStatisticsService.getStatus(
dto.statisticsId,
Expand Down

0 comments on commit 413a21c

Please sign in to comment.