summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-06-07 15:07:45 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-06-07 15:45:30 +0200
commitfac19ea38fbd46bf6d6636e9d12b555269788019 (patch)
tree3a54cd8f775eeb87ff4a0a2641b7eaa7d89694d6 /ishtar_common/utils.py
parentd3eb2d6fd52e393a7d3d841d66ecdf58b7a94b6a (diff)
downloadIshtar-fac19ea38fbd46bf6d6636e9d12b555269788019.tar.bz2
Ishtar-fac19ea38fbd46bf6d6636e9d12b555269788019.zip
⚡️ improve post treatments after imports
- check_cascade_update is now function which evaluate if cascade update is relevant - "_no_repost_save" attribute prevent a resave after post import - fix updat check for geo post save - add some logging
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 1757612ef..c6c14422c 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -23,6 +23,7 @@ import datetime
from functools import wraps
from itertools import chain
from inspect import currentframe, getframeinfo
+import logging
import hashlib
from importlib import import_module
import io
@@ -85,6 +86,7 @@ else:
)
_ = ugettext_lazy
+logger = logging.getLogger(__name__)
def dict_to_tuple(dct):
@@ -559,6 +561,7 @@ def _cached_label_changed(sender, **kwargs):
if not force_update and getattr(instance, "_cached_label_checked", False):
return
+ logger.debug(f"[ishtar] ishtar_common.utils._cached_label_changed - {instance.__class__.__name__} - {instance.pk} - {instance}")
if hasattr(instance, "refresh_cache"):
instance.refresh_cache()
@@ -587,8 +590,8 @@ def _cached_label_changed(sender, **kwargs):
if hasattr(instance, "_cascade_change") and instance._cascade_change:
instance.skip_history_when_saving = True
instance.__class__.objects.filter(pk=instance.pk).update(**dict(changed))
- if (getattr(instance, "FORCE_CASCADE_UPDATE", False) or changed
- or not cached_labels) and hasattr(instance, "cascade_update"):
+ if ((getattr(instance, "check_cascade_update", False) and instance.check_cascade_update())
+ or changed or not cached_labels) and hasattr(instance, "cascade_update"):
instance.cascade_update()
updated = False
if force_update or hasattr(instance, "update_search_vector"):
@@ -603,6 +606,7 @@ def _cached_label_changed(sender, **kwargs):
if hasattr(instance, "test_obj"):
item.test_obj = instance.test_obj
cached_label_changed(item.__class__, instance=item)
+
cache_key, __ = get_cache(sender, ["cached_label_changed", instance.pk])
cache.set(cache_key, None, settings.CACHE_TASK_TIMEOUT)
if cached_labels:
@@ -800,9 +804,10 @@ def _post_save_geodata(sender, **kwargs):
modified = False
if getattr(instance, "post_save_geo", False):
- instance.post_save_geo(save=False)
- modified = True
+ # TODO: geovectordata -> no post_save_geo: delete?
+ modified = instance.post_save_geo(save=False)
+ logger.debug(f"[ishtar] ishtar_common.utils._post_save_geodata - {instance.__class__.__name__} - {instance.pk} - {instance}")
# managed cached coordinates
cached_x, cached_y, cached_z = None, None, None
@@ -830,7 +835,7 @@ def _post_save_geodata(sender, **kwargs):
instance._no_move = True
instance.skip_history_when_saving = True
instance.save()
- cache_key, __ = get_cache(sender, ("post_save_geo", instance.pk))
+ cache_key, __ = get_cache(sender, ("post_save_geodata", instance.pk))
cache.set(cache_key, None, settings.CACHE_TASK_TIMEOUT)
return
@@ -858,12 +863,12 @@ def _post_save_geo(sender, **kwargs):
if getattr(instance, "_post_saved_geo", False):
return
+ logger.debug(f"[ishtar] ishtar_common.utils._post_save_geo - {instance.__class__.__name__} - {instance.pk} - {instance}")
instance._post_saved_geo = True
modified = False
if getattr(instance, "post_save_geo", False):
- instance.post_save_geo(save=False)
- modified = True
+ modified = instance.post_save_geo(save=False)
if hasattr(instance, "need_update") and instance.need_update:
instance.need_update = False