Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions backend/modules/tasks/queries/metrics-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function fetchTodayPlanTasks(visibleTasksWhere) {
'cancelled',
];

return await Task.findAll({
const tasks = await Task.findAll({
where: {
[Op.and]: [
visibleTasksWhere,
Expand All @@ -112,7 +112,7 @@ async function fetchTodayPlanTasks(visibleTasksWhere) {
{ defer_until: { [Op.lte]: now } },
],
},
// Exclude recurring parent tasks - only include non-recurring tasks or recurring instances
// Include non-recurring tasks, recurring parents, and recurring instances
{
[Op.or]: [
{
Expand All @@ -122,11 +122,21 @@ async function fetchTodayPlanTasks(visibleTasksWhere) {
[Op.or]: [
{ recurrence_type: 'none' },
{ recurrence_type: null },
{ recurrence_type: '' },
],
},
{ recurring_parent_id: null },
],
},
{
// Recurring parent tasks
[Op.and]: [
{ recurrence_type: { [Op.ne]: 'none' } },
{ recurrence_type: { [Op.ne]: null } },
{ recurrence_type: { [Op.ne]: '' } },
{ recurring_parent_id: null },
],
},
{
// Recurring instances (not parents)
recurring_parent_id: { [Op.ne]: null },
Expand All @@ -142,6 +152,18 @@ async function fetchTodayPlanTasks(visibleTasksWhere) {
['project_id', 'ASC'],
],
});

// Deduplicate: exclude recurring parents that already have instances in the list
const parentIdsWithInstances = new Set(
tasks
.filter((t) => t.recurring_parent_id)
.map((t) => t.recurring_parent_id)
);

return tasks.filter(
(t) =>
!parentIdsWithInstances.has(t.id) || t.recurring_parent_id !== null
);
}

async function fetchTasksDueToday(visibleTasksWhere, userTimezone) {
Expand Down
4 changes: 4 additions & 0 deletions backend/modules/tasks/queries/query-builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function filterTasksByParams(
[Op.or]: [
{ recurrence_type: 'none' },
{ recurrence_type: null },
{ recurrence_type: '' },
],
},
{ recurring_parent_id: null },
Expand All @@ -42,6 +43,7 @@ async function filterTasksByParams(
[Op.and]: [
{ recurrence_type: { [Op.ne]: 'none' } },
{ recurrence_type: { [Op.ne]: null } },
{ recurrence_type: { [Op.ne]: '' } },
{ recurring_parent_id: null },
{
[Op.or]: [
Expand Down Expand Up @@ -133,6 +135,7 @@ async function filterTasksByParams(
[Op.or]: [
{ recurrence_type: 'none' },
{ recurrence_type: null },
{ recurrence_type: '' },
],
},
{ recurring_parent_id: null },
Expand All @@ -145,6 +148,7 @@ async function filterTasksByParams(
[Op.and]: [
{ recurrence_type: { [Op.ne]: 'none' } },
{ recurrence_type: { [Op.ne]: null } },
{ recurrence_type: { [Op.ne]: '' } },
{ recurring_parent_id: null },
{ status: { [Op.in]: todayPlanStatuses } },
notDeferredCondition,
Expand Down