mcpField
D
django-pagination-performance

django-pagination-performance

github.com/lvtd-llcDevelopment162 installsUpdated 7w ago
Repository

About django-pagination-performance

A workflow skill for Django developers diagnosing slow list views and APIs as pages grow deeper. It helps select pagination strategies by clarifying requirements, measuring queries, and checking deterministic ordering.

Key features

  1. 01Clarify pagination requirements
  2. 02Measure page and count queries
  3. 03Choose offset or cursor pagination
  4. 04Set stable indexed ordering
  5. 05Verify deep-page behavior

Use cases

  1. 01Speed up large Django feeds
  2. 02Limit costly deep page access
  3. 03Diagnose inconsistent page results

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/lvtd-llc/skills --skill django-pagination-performance

After installing, type/django-pagination-performancein Claude Code to confirm it loaded.

Bundled filesreferences/pagination-patterns.md

Details

From the project README

Django Pagination Performance

Use this skill when a Django list view or API slows down as pages get deeper or result sets grow. Pagination is a query-design problem as much as a response-shaping problem.

Workflow

  1. Confirm the list contract.

    • Is arbitrary page access required, or only next/previous?
    • Does the UI need a total count?
    • Can ordering be fixed and stable?
    • What page size limit is acceptable?
  2. Measure the current query.

    • Capture SQL for the page query and count query.
    • Check ordering, indexes, and high page numbers.
    • Use QuerySet.explain() for deep pages.
  3. Choose the pagination style.

    • Use Django Paginator for moderate result sets and arbitrary page access.
    • Use capped offset pagination when page numbers are useful but deep pages should be limited.
    • Use keyset/cursor pagination for large feeds, timelines, logs, and infinite scroll.
    • Use DRF CursorPagination for API next/previous navigation with stable ordering.
  4. Make ordering deterministic.

    • Use a unique or nearly unique immutable ordering field.
    • Add a primary-key tie breaker when needed.
    • Ensure the index matches filters plus ordering.

See pagination-patterns.md for Django and DRF examples.

Safety Notes

  • Deep LIMIT/OFFSET pages can be slow because the database still walks skipped rows.
  • Unordered querysets produce inconsistent pages.
  • Cursor pagination restricts arbitrary page jumps and user-controlled ordering.
  • Large exact counts can dominate list latency.

Verification

Measure first page, representative deep page, count query, and insertion/deletion consistency for the chosen pagination contract.

Comments

Markdown supported