Opened 13 days ago
Closed 12 days ago
#35975 closed Uncategorized (duplicate)
New feature: faster fixture loading via loaddata command
Reported by: | JorisBenschop | Owned by: | JorisBenschop |
---|---|---|---|
Component: | Core (Management commands) | Version: | 5.1 |
Severity: | Normal | Keywords: | loaddata |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As per this forum discussion, I have created a patch to improve load times for the loaddata command under some circumstances.
Currently the “loaddata” management command uses the obj.save() method for each deserialized object within a fixture. This function first tries an UPDATE statement and, if that fails, tries an INSERT statement.
I propose to add two optional flags to the loaddata command:
–force-insert adds the “force_insert=True” to the save() method. This reduces load time by ~50% but has an increased risk of the upload failing in case the record already exists.
–bulk_create: This option groups records in the fixture by the model, and insert the group as a single bulk_create statement. For large fixtures, I have achieved a 1000-fold improvement in loading time. It has a number of risks (already described in the bulk_create section), notably that it skips some routines covered in the save() method of the model.
Both these flags are supposed to be run by people who know that above-mentioned issues will not be a problem for them, and should not be enabled by default.
Change History (3)
comment:1 by , 13 days ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:2 by , 13 days ago
Component: | Uncategorized → Core (Management commands) |
---|
comment:3 by , 12 days ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
Duplicate of #35904