Problem
The toggleTask function in public/app.js first makes a GET /api/tasks/:id to fetch the full task record, then immediately makes a PUT /api/tasks/:id with the merged data. This doubles the network round-trips on every checkbox toggle. The task data is already available in the allTasks array in memory.
Recommendation
Look up the task directly from the in-memory allTasks array instead of doing an extra GET request:
async function toggleTask(id, completed) {
const task = allTasks.find(t => t.id === id);
if (!task) return;
// proceed with PUT using task data
}
Alternatively, add a PATCH /api/tasks/:id endpoint that accepts only the completed field, avoiding the need to re-send the full record.
Location: public/app.js — toggleTask function (around line 407)
Severity: medium
Problem
The
toggleTaskfunction inpublic/app.jsfirst makes aGET /api/tasks/:idto fetch the full task record, then immediately makes aPUT /api/tasks/:idwith the merged data. This doubles the network round-trips on every checkbox toggle. The task data is already available in theallTasksarray in memory.Recommendation
Look up the task directly from the in-memory
allTasksarray instead of doing an extra GET request:Alternatively, add a
PATCH /api/tasks/:idendpoint that accepts only thecompletedfield, avoiding the need to re-send the full record.Location:
public/app.js—toggleTaskfunction (around line 407)Severity: medium