1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Remove local caching attempt

This commit is contained in:
Jeremy Stretch
2020-05-08 10:05:05 -04:00
parent 2c19390d7c
commit e3be5f8468

View File

@ -1,3 +1,4 @@
import logging
from collections import OrderedDict
from datetime import date
@ -57,31 +58,16 @@ class CustomFieldModel(models.Model):
class CustomFieldManager(models.Manager):
use_in_migrations = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Initialize a cache for fetched CustomFields
self._cache = {}
def get_for_model(self, model):
"""
Return all CustomFields assigned to the given model.
"""
model = model._meta.concrete_model
# First try to return from cache
try:
return self._cache[model]
except KeyError:
pass
# Fetch from the database if the model's CustomFields have not been cached
content_type = ContentType.objects.get_for_model(model)
customfields = CustomField.objects.filter(obj_type=content_type)
# Cache the retrieved CustomFields
self._cache[model] = customfields
return customfields