﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35407	Cache Model._meta.swapped	Adam Johnson	nobody	"Another candidate for caching, like #35232 before.

The `Model._meta.swapped` property returns the model that this one has been swapped for. Since most models are not swappable (only `auth.User` is officially swappable), it returns `None` in nearly all cases.

I found this property was the most called function in Django when profiling a subset of Django’s tests, with:

{{{
$ python -m cProfile -o profile runtests.py --parallel 1 *model*

$ python -m pstats profile <<< 'sort ncalls
stats 10000' | less
}}}

This showed 439,484 calls to `swapped`, taking 29ms of the 5.597s test run, or 0.5% of the total runtime.

After adding `@cached_property`, this is reduced to 3,653 calls, rounding down to 0ms."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
