mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +00:00
[1.9.x] 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.
Backport of ee9f4686b1 from master
This commit is contained in:
committed by
Tim Graham
parent
b37cb0b958
commit
99569b22d9
14
tests/fixtures/tests.py
vendored
14
tests/fixtures/tests.py
vendored
@@ -13,7 +13,7 @@ from django.core.files.temp import NamedTemporaryFile
|
||||
from django.core.serializers.base import ProgressBar
|
||||
from django.db import IntegrityError, connection
|
||||
from django.test import (
|
||||
TestCase, TransactionTestCase, ignore_warnings, skipUnlessDBFeature,
|
||||
TestCase, TransactionTestCase, ignore_warnings, mock, skipUnlessDBFeature,
|
||||
)
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
@@ -643,6 +643,18 @@ class NonExistentFixtureTests(TestCase):
|
||||
self.assertEqual(force_text(w[0].message),
|
||||
"No fixture named 'this_fixture_doesnt_exist' found.")
|
||||
|
||||
@mock.patch('django.db.connection.enable_constraint_checking')
|
||||
@mock.patch('django.db.connection.disable_constraint_checking')
|
||||
def test_nonexistent_fixture_no_constraint_checking(self,
|
||||
disable_constraint_checking, enable_constraint_checking):
|
||||
"""
|
||||
If no fixtures match the loaddata command, constraints checks on the
|
||||
database shouldn't be disabled. This is performance critical on MSSQL.
|
||||
"""
|
||||
management.call_command('loaddata', 'this_fixture_doesnt_exist', verbosity=0)
|
||||
disable_constraint_checking.assert_not_called()
|
||||
enable_constraint_checking.assert_not_called()
|
||||
|
||||
|
||||
class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user