From d37a734379c52b8ad7edc983e3b06a7f3cdb79b6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 27 Jan 2023 11:10:37 +0900 Subject: [PATCH] fix(server): fix aggregation of retention --- .../processors/AggregateRetentionProcessorService.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/queue/processors/AggregateRetentionProcessorService.ts b/packages/backend/src/queue/processors/AggregateRetentionProcessorService.ts index 4650da76bb..da4ae88557 100644 --- a/packages/backend/src/queue/processors/AggregateRetentionProcessorService.ts +++ b/packages/backend/src/queue/processors/AggregateRetentionProcessorService.ts @@ -57,8 +57,15 @@ export class AggregateRetentionProcessorService { usersCount: targetUserIds.length, }); + // 今日活動したユーザーを全て取得 + const activeUsers = await this.usersRepository.findBy({ + host: IsNull(), + lastActiveDate: MoreThan(new Date(Date.now() - (1000 * 60 * 60 * 24))), + }); + const activeUsersIds = activeUsers.map(u => u.id); + for (const record of pastRecords) { - const retention = record.userIds.filter(id => targetUserIds.includes(id)).length; + const retention = record.userIds.filter(id => activeUsersIds.includes(id)).length; const data = deepClone(record.data); data[dateKey] = retention;