Opened 3 years ago
Last modified 3 years ago
#33636 closed New feature
BulkProcessMixin on models.Model — at Initial Version
Reported by: | Myung Eui Yoon | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.0 |
Severity: | Normal | Keywords: | bulk, model |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
""" class BulkyModel(models.Model, ModelBulkProcessMixin): id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=10, null=False) With ModelBulkProcessMixin , We could minimize memory usage. Without ModelBulkProcessMixin, We shold maintain bulk array size up to 100_000 or manually maintain arraysize up to batch_size like 10_000 if len(chunked_list)>10_000: Model.objects.bulk_create(chunked_list) and check remain in list again at the end. if len(chunked_list)>0: Model.objects.bulk_create(chunked_list) """ names = [f"name-{num}" for num in range(100_000)] with BulkyModel.gen_bulk_create(batch_size=10_000) as bulk: for name in names: bulk.add(BulkyModel(name=name)) self.assertEqual(100_000, BulkyModel.objects.all().count())
Note:
See TracTickets
for help on using tickets.