Introduce a CustomFieldManager to cache custom fields for each content type #3226
Labels
status: accepted
This issue has been accepted for implementation
type: housekeeping
Changes to the application which do not directly impact the end user
Milestone
Proposed Changes
Currently, retrieving the custom fields for an object is done by calling
get_custom_fields()
on that object. This method begins by finding all CustomFields assigned to the object's ContentType:As pointed out in #3185, this results in a new database query for each call. This can be highly inefficient, for example, when accessing the custom fields for each device in a list of devices.
We should implement a CustomFieldManager similar to Django's ContentTypeManager which would allow us to cache the available custom fields for each model.
Justification
Utilizing a manager which caches the custom fields for each content type will avoid redundant database access and greatly improve performance where custom fields are accessed in export templates and reports. It will likely also simplify CustomFieldModelSerializer.
The text was updated successfully, but these errors were encountered: