Skip to content

toggleTask makes an unnecessary extra HTTP GET on every checkbox toggle #12

Description

@sbley

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.jstoggleTask function (around line 407)
Severity: medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions