This method should be cached to speed up rendering in migrations. The
`Field` instances are constantly copied, so that's not a good place, but
it always uses `django.apps.apps`. Moving this looping over models to
`Apps.get_swappable_setting` and using an `lru_cache` speeds up rendering
quite a bit.
Both `AUTH_USER_MODEL` and the models contained in the main `apps`
instance should never change, except for testing scenario's. The cache
should never have to be cleared in non-testing scenario's, which results
in another very significant speed-up, for a total of about 35% faster
rendering in my benchmarks.
--
Ticket URL: <https://code.djangoproject.com/ticket/24590>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
PR: https://github.com/django/django/pull/4459
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:2>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:3>
* status: new => assigned
* owner: knbk => MarkusH
Comment:
I updated the existing PR: https://github.com/django/django/pull/5176
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:4>
* needs_docs: 0 => 1
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:5>
* needs_docs: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e1427cc609fa6ab247501b101cfb3c0092aba55b" e1427cc6]:
{{{
#!CommitTicketReference repository=""
revision="e1427cc609fa6ab247501b101cfb3c0092aba55b"
Fixed #24590 -- Cached calls to swappable_setting.
Moved the lookup in Field.swappable_setting to Apps, and added
an lru_cache to cache the results.
Refs #24743
Thanks Marten Kenbeek for the initial work on the patch. Thanks Aymeric
Augustin and Tim Graham for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:8>
* has_patch: 1 => 0
* stage: Ready for checkin => Accepted
Comment:
Looks like the new tests aren't isolated as they fail in reverse: `$
./tests/runtests.py --reverse migrations`
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:9>
* status: closed => new
* resolution: fixed =>
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:10>
Comment (by MarkusH):
This change isolates the tests in `migrations` that rely on a replaced
swappable model: https://github.com/django/django/pull/5199
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:11>
Comment (by Markus Holtermann <info@…>):
In [changeset:"8e631a3175f145dbf3eec269f8e3c59a1520540f" 8e631a3]:
{{{
#!CommitTicketReference repository=""
revision="8e631a3175f145dbf3eec269f8e3c59a1520540f"
Refs #24590 -- Ensured isolation between autodetector tests
Fixed a regression introduced in e1427cc609fa6ab247501b101cfb3c0092aba55b
when running tests in reverse order.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:12>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/24590#comment:13>