About django-queryset-batch-processing
A skill for Django developers processing large numbers of database rows. It guides read and write patterns, batch sizing, and safety checks to limit unnecessary model loading and queryset caching while preserving required behavior.
Key features
- 01Choose scalar or iterator reads
- 02Use set-based bulk writes
- 03Control batch and transaction size
- 04Account for skipped hooks and signals
- 05Measure throughput, memory, and correctness
Use cases
- 01Building exports or reports over many rows
- 02Updating many records efficiently
- 03Running production jobs with bounded batches
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ lvtd-llc/ skills --skill django-queryset-batch-processingAfter installing, type/django-queryset-batch-processingin Claude Code to confirm it loaded.
Bundled filesreferences/batch-patterns.md
Details
From the project READMEDjango QuerySet Batch Processing
Use this skill when Django code processes many rows. The goal is to avoid loading unnecessary model instances, avoid queryset result-cache blowups, and move writes into set-based database operations when behavior allows.
Workflow
-
Identify the per-row work.
- Is it read-only export/reporting?
- Does it need model methods, validation, or signals?
- Can the database compute or update the value directly?
-
Choose the read pattern.
- Use
values()orvalues_list()for scalar exports and reports. - Use
iterator(chunk_size=...)when model instances are needed but queryset caching is not. - Keep ordering deliberate; unnecessary ordering costs work.
- Use
-
Choose the write pattern.
- Use
QuerySet.update()withF()or expressions for uniform updates. - Use
bulk_update()when each object has a different value. - Use
bulk_create()for inserts, with conflict options only when the project supports their semantics. - Fall back to per-instance
save()only when hooks, validation, side effects, or signals are required.
- Use
-
Control batch size.
- Keep transactions bounded.
- Avoid huge
INlists and oversizedCASEupdates. - Monitor locks, replication lag, and memory for production jobs.
See batch-patterns.md for examples and caveats.
Safety Notes
- Bulk update/delete operations do not call each model instance's
save()ordelete()methods. - Bulk operations can skip application-level side effects and signals.
- Long transactions can hold locks and delay vacuum or replication.
Verification
Measure rows processed per second, query count, memory, transaction duration, and correctness on a representative batch.