mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 16:26:09 -06:00
Clear any pre-existing cached entries on cache()
This commit is contained in:
parent
607312a456
commit
a237b2a10b
@ -180,20 +180,27 @@ class CachedValueSearchBackend(SearchBackend):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cache(cls, instance, data):
|
def cache(cls, instance, data):
|
||||||
|
ct = ContentType.objects.get_for_model(instance)
|
||||||
|
|
||||||
|
# Wipe out any previously cached values for the object
|
||||||
|
CachedValue.objects.filter(object_type=ct, object_id=instance.pk).delete()
|
||||||
|
|
||||||
|
# Record any new non-empty values
|
||||||
|
cached_values = []
|
||||||
for field in data:
|
for field in data:
|
||||||
if not field.value:
|
if not field.value:
|
||||||
continue
|
continue
|
||||||
ct = ContentType.objects.get_for_model(instance)
|
cached_values.append(
|
||||||
CachedValue.objects.update_or_create(
|
CachedValue(
|
||||||
defaults={
|
object_type=ct,
|
||||||
'value': field.value,
|
object_id=instance.pk,
|
||||||
'weight': field.weight,
|
field=field.name,
|
||||||
},
|
type=field.type,
|
||||||
object_type=ct,
|
weight=field.weight,
|
||||||
object_id=instance.pk,
|
value=field.value
|
||||||
field=field.name,
|
)
|
||||||
type=field.type
|
|
||||||
)
|
)
|
||||||
|
CachedValue.objects.bulk_create(cached_values)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def remove(cls, instance):
|
def remove(cls, instance):
|
||||||
|
Loading…
Reference in New Issue
Block a user