Skip to content

Optimize tasks route: add pagination, filtering, caching, and database indexes#16

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/optimize-tasks-route
Draft

Optimize tasks route: add pagination, filtering, caching, and database indexes#16
Copilot wants to merge 5 commits intomasterfrom
copilot/optimize-tasks-route

Conversation

Copy link

Copilot AI commented Mar 26, 2026

Tasks route was loading entire dataset on every request without filtering or pagination, causing performance degradation at scale.

Changes

Database Layer

  • Indexes: Added idx_tasks_priority, idx_tasks_completed, idx_tasks_created_at DESC for query optimization
  • Dynamic updates: updateTask() now builds SQL dynamically to only update provided fields
  • Conditional WHERE: Replaced WHERE 1=1 pattern with proper conditional clause construction
  • Count query: Added getTaskCount() for pagination metadata

API Enhancements

  • Pagination: GET /api/tasks accepts ?page=N&limit=M (default: page=1, limit=50, max=100)
    • Returns { tasks: [...], pagination: { page, limit, totalCount, totalPages, hasNextPage, hasPrevPage } }
    • Queries for tasks and count run in parallel
  • Filtering: ?priority={low|medium|high} and ?completed={0|1} with validation
  • Caching: In-memory cache for GET /api/tasks/:id with 60s TTL, invalidated on updates/deletes
  • Compression: gzip middleware for response size reduction

Example

# Paginated high-priority incomplete tasks
GET /api/tasks?priority=high&completed=0&page=1&limit=25

# Response includes metadata
{
  "tasks": [...],
  "pagination": {
    "page": 1,
    "limit": 25,
    "totalCount": 150,
    "totalPages": 6,
    "hasNextPage": true,
    "hasPrevPage": false
  }
}

Backward Compatibility

All query parameters optional. Existing clients unaffected.

Tests

Added 11 tests covering pagination validation, filter validation, cache behavior, and compression support. All 35 tests passing. CodeQL: 0 alerts.

Original prompt

This section details on the original issue you should resolve

<issue_title>Optimize the tasks route</issue_title>
<issue_description>The tasks route needs to be optimized for better performance and scalability. Review the current implementation, identify bottlenecks, and refactor the code to improve efficiency. Consider database query optimization, caching, and minimizing response times.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits March 26, 2026 07:03
Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
Agent-Logs-Url: https://github.com/CanarysPlayground/TaskManagerApp/sessions/3a744bda-fd40-4e4d-8ba4-b926d7f653fe
…ching, and compression

Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
Agent-Logs-Url: https://github.com/CanarysPlayground/TaskManagerApp/sessions/3a744bda-fd40-4e4d-8ba4-b926d7f653fe
Copilot AI changed the title [WIP] Optimize tasks route for better performance and scalability Optimize tasks route: add pagination, filtering, caching, and database indexes Mar 26, 2026
Copilot AI requested a review from kavyashri-as March 26, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize the tasks route

2 participants