mirror of https://github.com/django/django.git
Refs #31051 -- Optimized serialize_db_to_string() by avoiding creation of models list.
This commit is contained in:
parent
289d0ec6fd
commit
75520e1767
|
@ -97,24 +97,24 @@ class BaseDatabaseCreation:
|
||||||
Designed only for test runner usage; will not handle large
|
Designed only for test runner usage; will not handle large
|
||||||
amounts of data.
|
amounts of data.
|
||||||
"""
|
"""
|
||||||
# Build list of all models to serialize.
|
# Iteratively return every object for all models to serialize.
|
||||||
|
def get_objects():
|
||||||
from django.db.migrations.loader import MigrationLoader
|
from django.db.migrations.loader import MigrationLoader
|
||||||
loader = MigrationLoader(self.connection)
|
loader = MigrationLoader(self.connection)
|
||||||
model_list = []
|
|
||||||
for app_config in apps.get_app_configs():
|
for app_config in apps.get_app_configs():
|
||||||
if (
|
if (
|
||||||
app_config.models_module is not None and
|
app_config.models_module is not None and
|
||||||
app_config.label in loader.migrated_apps and
|
app_config.label in loader.migrated_apps and
|
||||||
app_config.name not in settings.TEST_NON_SERIALIZED_APPS
|
app_config.name not in settings.TEST_NON_SERIALIZED_APPS
|
||||||
):
|
):
|
||||||
model_list.extend(app_config.get_models())
|
for model in app_config.get_models():
|
||||||
|
if (
|
||||||
# Make a function to iteratively return every object
|
model._meta.can_migrate(self.connection) and
|
||||||
def get_objects():
|
router.allow_migrate_model(self.connection.alias, model)
|
||||||
for model in model_list:
|
):
|
||||||
if (model._meta.can_migrate(self.connection) and
|
queryset = model._default_manager.using(
|
||||||
router.allow_migrate_model(self.connection.alias, model)):
|
self.connection.alias,
|
||||||
queryset = model._default_manager.using(self.connection.alias).order_by(model._meta.pk.name)
|
).order_by(model._meta.pk.name)
|
||||||
yield from queryset.iterator()
|
yield from queryset.iterator()
|
||||||
# Serialize to a string
|
# Serialize to a string
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
|
|
Loading…
Reference in New Issue