Andrew Godwin avatar Andrew Godwin committed e8cad54

Fixed #1225: List migration query speedup. Thanks to Dan MCGee.

Comments (0)

Files changed (1)


     applied_migrations = MigrationHistory.objects.filter(app_name__in=[app.app_label() for app in apps])
     if database != DEFAULT_DB_ALIAS:
         applied_migrations = applied_migrations.using(database)
-    applied_migration_names = ['%s.%s' % (mi.app_name,mi.migration) for mi in applied_migrations]
+    applied_migrations_lookup = dict(('%s.%s' % (mi.app_name, mi.migration), mi) for mi in applied_migrations)
     for app in apps:
         print(" " + app.app_label())
         # Get the migrations object
         for migration in app:
-            if migration.app_label() + "." + in applied_migration_names:
-                applied_migration = applied_migrations.get(app_name=migration.app_label(),
+            full_name = migration.app_label() + "." +
+            if full_name in applied_migrations_lookup:
+                applied_migration = applied_migrations_lookup[full_name]
                 print(format_migration_list_item(, applied=applied_migration.applied, **options))
                 print(format_migration_list_item(, applied=False, **options))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.