Opened 4 years ago

Closed 4 years ago

Last modified 11 months ago

#27666 closed Cleanup/optimization (fixed)

Delay rendering of models in migration operations when possible

Reported by: Markus Holtermann Owned by: Markus Holtermann
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Markus Holtermann)

As it turns out, when we delay the rendering of related models up to the point where it's necessary (just before RunPython, afaict), we can cut down migration time to a quarter and maybe more:


Given that 3rd party migration operations may need to enforce model rendering like we do for RunPython, we probably need to treat this as a backwards incompatible change, I suppose.

    def database_forwards(self, app_label, schema_editor, from_state, to_state):
        if from_state.is_delayed and 'apps' in from_state.__dict__:
            del from_state.__dict__['apps']
        # ...

Change History (7)

comment:1 Changed 4 years ago by Markus Holtermann

Owner: changed from nobody to Markus Holtermann
Status: newassigned

comment:2 Changed 4 years ago by Markus Holtermann

Triage Stage: UnreviewedAccepted

comment:3 Changed 4 years ago by Markus Holtermann

Description: modified (diff)

comment:4 Changed 4 years ago by Markus Holtermann

Needs documentation: unset

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 45ded05:

Fixed #27666 -- Delayed rendering of recursivly related models in migration operations.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

In 46e0335:

Refs #27666 -- Added ProjectState.reload_models().

comment:7 Changed 11 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 1d16c5d:

Refs #27666 -- Ensured relationship consistency on delayed reloads.

Delayed reloads of state models broke identity based relationships
between direct and non-direct ancestors.

Basing models.Options related objects map of model labels instead of
their identity ensured relationship consistency is maintained.

Refs #30966.

Co-authored-by: Hasan Ramezani <hasan.r67@…>

Note: See TracTickets for help on using tickets.
Back to Top