跳到主要内容
知仓学习社ZHICANG

django-queryset-batch-processing

Process large Django querysets and write-heavy jobs with memory-safe reads, values/values_list, iterator chunking, set-based update/delete, bulk_cre…

不碰外部(只输出文字)无严重或高危命中hashgraph-online/awesome-codex-plugins

它会碰到什么

扫了多少2 个文本文件,5 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Django 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

  1. 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?
  1. Choose the read pattern.
  • Use values() or values_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.
  1. Choose the write pattern.
  • Use QuerySet.update() with F() 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.
  1. Control batch size.
  • Keep transactions bounded.
  • Avoid huge IN lists and oversized CASE updates.
  • Monitor locks, replication lag, and memory for production jobs.

See [batch-patterns.md](references/batch-patterns.md) for examples and caveats.

Safety Notes

  • Bulk update/delete operations do not call each model instance's save() or delete() 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.

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 1,027
本站分层T1
该仓技能数1910
原文件路径plugins/LVTD-LLC/skills/skills/django-queryset-batch-processing/SKILL.md

同一个仓库里的其他技能

看这个仓库的全部 1910 个技能