mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #23372 -- Made loaddata faster if it doesn't find any fixtures.
Django's test suite often tries to load fixture files from apps that have no fixtures at all. This creates a lot of unnecessary disabling and enabling of constraints which can be expensive on some database. To speed this up, loaddata now first checks if any fixture file matches. If no fixture file is matched, then the command exits before disabling and enabling of constraints is done. The main benefit of this change is seen on MSSQL, where tests on Django 1.8 run hours faster.
This commit is contained in:
committed by
Tim Graham
parent
6687f4dcbb
commit
ee9f4686b1
@@ -85,6 +85,16 @@ class Command(BaseCommand):
|
||||
if has_bz2:
|
||||
self.compression_formats['bz2'] = (bz2.BZ2File, 'r')
|
||||
|
||||
# Django's test suite repeatedly tries to load initial_data fixtures
|
||||
# from apps that don't have any fixtures. Because disabling constraint
|
||||
# checks can be expensive on some database (especially MSSQL), bail
|
||||
# out early if no fixtures are found.
|
||||
for fixture_label in fixture_labels:
|
||||
if self.find_fixtures(fixture_label):
|
||||
break
|
||||
else:
|
||||
return
|
||||
|
||||
with connection.constraint_checks_disabled():
|
||||
for fixture_label in fixture_labels:
|
||||
self.load_label(fixture_label)
|
||||
|
||||
Reference in New Issue
Block a user