Skip to content

Commit 8b74a52

Browse files
authored
Merge branch 'develop' into fetch-logs
2 parents ef38a67 + 46bc908 commit 8b74a52

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

models/tasks.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {
2222
} = TASK_STATUS;
2323
const { OLD_ACTIVE, OLD_BLOCKED, OLD_PENDING, OLD_COMPLETED } = TASK_STATUS_OLD;
2424
const { INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
25+
const { BATCH_SIZE_IN_CLAUSE } = require("../constants/firebase");
2526

2627
/**
2728
* Update multiple tasks' status to DONE in one batch operation.
@@ -750,11 +751,22 @@ const fetchIncompleteTasksByUserIds = async (userIds) => {
750751
return [];
751752
}
752753
try {
753-
const incompleteTasksQuery = await tasksModel.where("assigneeId", "in", userIds).get();
754+
const userIdChunks = [];
754755

755-
const incompleteTaskForUsers = incompleteTasksQuery.docs.filter(
756-
(task) => !COMPLETED_STATUSES.includes(task.data().status)
757-
);
756+
for (let i = 0; i < userIds.length; i += BATCH_SIZE_IN_CLAUSE) {
757+
userIdChunks.push(userIds.slice(i, i + BATCH_SIZE_IN_CLAUSE));
758+
}
759+
760+
const promises = userIdChunks.map(async (userIdChunk) => {
761+
const querySnapshot = await tasksModel.where("assignee", "in", userIdChunk).get();
762+
return querySnapshot.docs.map((doc) => doc.data());
763+
});
764+
765+
const snapshots = await Promise.all(promises);
766+
767+
const incompleteTasks = snapshots.flat();
768+
769+
const incompleteTaskForUsers = incompleteTasks.filter((task) => !COMPLETED_STATUSES.includes(task.status));
758770

759771
return incompleteTaskForUsers;
760772
} catch (error) {

services/tasks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ const fetchOrphanedTasks = async () => {
6666

6767
const userIds = userSnapshot.docs.map((doc) => doc.id);
6868

69-
const orphanedTasksQuerySnapshot = await tasksQuery.fetchIncompleteTasksByUserIds(userIds);
69+
const orphanedTasksData = await tasksQuery.fetchIncompleteTasksByUserIds(userIds);
7070

71-
if (orphanedTasksQuerySnapshot.empty) {
71+
if (orphanedTasksData.empty) {
7272
return [];
7373
}
7474

75-
const orphanedTasks = orphanedTasksQuerySnapshot.map((doc) => doc.data());
75+
const orphanedTasks = orphanedTasksData;
7676

7777
return orphanedTasks;
7878
} catch (error) {

services/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const getUsersWithIncompleteTasks = async (users) => {
1515
return [];
1616
}
1717

18-
const userIdsWithIncompleteTasks = new Set(abandonedTasksQuerySnapshot.map((doc) => doc.data().assigneeId));
18+
const userIdsWithIncompleteTasks = new Set(abandonedTasksQuerySnapshot.map((doc) => doc.assignee));
1919

2020
const eligibleUsersWithTasks = users.filter((user) => userIdsWithIncompleteTasks.has(user.id));
2121

test/fixtures/abandoned-tasks/departed-users.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ const tasksData = [
7676
updatedAt: 1727027999,
7777
startedOn: 1727027777,
7878
endsOn: 1731542400,
79-
assignee: "archived_user1",
80-
assigneeId: "user1_id",
79+
assignee: "user1_id",
8180
github: {
8281
issue: {
8382
html_url: "https://github.com/org/repo/issues/1",
@@ -97,8 +96,7 @@ const tasksData = [
9796
updatedAt: 1727027999,
9897
startedOn: 1727027777,
9998
endsOn: 1731542400,
100-
assignee: "archived_user2",
101-
assigneeId: "user2_id",
99+
assignee: "user2_id",
102100
github: {
103101
issue: {
104102
html_url: "https://github.com/org/repo/issues/2",
@@ -118,8 +116,7 @@ const tasksData = [
118116
updatedAt: 1727027999,
119117
startedOn: 1727027777,
120118
endsOn: 1731542400,
121-
assignee: "archived_user1",
122-
assigneeId: "user1_id",
119+
assignee: "user1_id",
123120
github: {
124121
issue: {
125122
html_url: "https://github.com/org/repo/issues/3",
@@ -139,8 +136,7 @@ const tasksData = [
139136
updatedAt: 1727027999,
140137
startedOn: 1727027777,
141138
endsOn: 1731542400,
142-
assignee: "active_user",
143-
assigneeId: "user3_id",
139+
assignee: "user3_id",
144140
github: {
145141
issue: {
146142
html_url: "https://github.com/org/repo/issues/4",

0 commit comments

Comments
 (0)