Hi Carlton,

Adam asked me to take a look at this. I've run it on our codebase with 
~1100 migrations and ~380 apps.

Running on Django 2.1, the results of this script (the updated version) are:

> 1min 23s ± 1.1 s per loop (mean ± std. dev. of 7 runs, 1 loop each)


Running on the branch, installed with [1], the results are:

> 1min 20s ± 524 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

There were no exceptions thrown - the script completed cleanly, although I 
haven't actually migrated with it or checked that the migrations work. I 
assume the script is enough to ensure consistent migrations? Around a 3.5% 
speedup.

I hope this is what you were looking for, apologies if I've got something 
wrong - I'm lacking full context on this. Hope this helps!


Dan


[1]: pip install 
https://github.com/monoidal/django/archive/optimize_migrations.zip




On Monday, 20 August 2018 10:54:29 UTC+1, Carlton Gibson wrote:
>
> Making the script less noisy here I commented out the actual work.
> (So it didn't function as a test.) 
> (No comment. 😐)
>
> Corrected version:
>
> ```
> import sys
>
> from django.db import connection
> from django.db.migrations.loader import MigrationLoader
>
> loader = MigrationLoader(connection)
>
> backwards = loader.graph.root_nodes()
> forwards = loader.graph.leaf_nodes()
>
> print('Calculating backward plans:')
> for root in backwards:
>     loader = MigrationLoader(connection)
>     sys.stdout.write('.')
>     plan = loader.graph.backwards_plan(root)
>     #print(plan)
> sys.stdout.write('\n')
> print('Calculating forward plans:')
> for leaf in forwards:
>     loader = MigrationLoader(connection)
>     sys.stdout.write('.')
>     plan = loader.graph.forwards_plan(leaf)
>     # print(plan)
>
> sys.stdout.write('\nRun Done\n\n')
>
> ```
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/cab6baa9-bb5f-42c7-be8b-0223b36cf826%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to