summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-11-13 18:55:30 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-11-14 16:57:37 +0100
commitd0d146cc099bfe2d58a8c8ec6e57096661d1fdcb (patch)
tree1007a19ed094bb463a9234909d84412a379a3c9c /ishtar_common/utils.py
parent1d1fd6c794c8ca8e758fc416b43e0f881136057f (diff)
downloadIshtar-d0d146cc099bfe2d58a8c8ec6e57096661d1fdcb.tar.bz2
Ishtar-d0d146cc099bfe2d58a8c8ec6e57096661d1fdcb.zip
⚡️ improve parcel post-treatments - add timestamp to prevent multiple geo and cached_label edition
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index bbefd085e..d5ace858d 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -487,6 +487,7 @@ EXTRA_KWARGS_TRIGGER = [
"_post_saved_geo",
"_search_updated",
"_cached_label_checked",
+ "_timestamp",
]
@@ -549,6 +550,9 @@ def cached_label_changed(sender, **kwargs):
instance = kwargs["instance"]
if not instance:
return
+ if hasattr(instance, "_timestamp") and hasattr(instance, "timestamp_label") and (
+ instance.timestamp_label or 0) >= (instance._timestamp or 0):
+ return
if hasattr(instance, "external_id") and hasattr(instance, "auto_external_id") \
and hasattr(instance, "SLUG") and not getattr(instance, "_external_id_checked", None):
changed = load_task(_external_id_changed, "external_id_changed", None, sender, **kwargs)
@@ -581,6 +585,11 @@ def _cached_label_changed(sender, **kwargs):
if not force_update and getattr(instance, "_cached_label_checked", False):
return
+ if hasattr(instance, "_timestamp") and hasattr(instance, "timestamp_label"):
+ if (instance.timestamp_label or 0) >= (instance._timestamp or 0):
+ return
+ instance.__class__.objects.filter(pk=instance.pk).update(timestamp_label=instance._timestamp)
+
logger.debug(f"[ishtar] ishtar_common.utils._cached_label_changed - {instance.__class__.__name__} - {instance.pk} - {instance}")
if hasattr(instance, "refresh_cache"):
instance.refresh_cache()
@@ -625,6 +634,8 @@ def _cached_label_changed(sender, **kwargs):
item._cascade_change = True
if hasattr(instance, "test_obj"):
item.test_obj = instance.test_obj
+ if instance.timestamp_label:
+ item._timestamp = instance.timestamp_label
cached_label_changed(item.__class__, instance=item)
cache_key, __ = get_cache(sender, ["cached_label_changed", instance.pk])
@@ -672,9 +683,12 @@ def _external_id_changed(sender, **kwargs):
if not instance.external_id or instance.auto_external_id:
external_id = get_generated_id(instance.SLUG + "_external_id", instance)
if external_id != instance.external_id:
- updated = True
- instance.auto_external_id = True
- instance.external_id = external_id
+ try:
+ instance.auto_external_id = True
+ instance.external_id = external_id
+ updated = True
+ except AttributeError:
+ pass
if hasattr(instance, "regenerate_all_ids"):
updated |= instance.regenerate_all_ids(save=False) or False
instance._external_id_checked = True
@@ -909,6 +923,11 @@ def _post_save_geo(sender, **kwargs):
if getattr(instance, "_post_saved_geo", False):
return
+ if hasattr(instance, "_timestamp") and hasattr(instance, "timestamp_geo"):
+ if (instance.timestamp_label or 0) >= (instance._timestamp or 0):
+ return
+ instance.__class__.objects.filter(pk=instance.pk).update(timestamp_geo=instance._timestamp)
+
logger.debug(f"[ishtar] ishtar_common.utils._post_save_geo - {instance.__class__.__name__} - {instance.pk} - {instance}")
instance._post_saved_geo = True
@@ -1964,7 +1983,7 @@ def get_current_profile(force=False):
return IshtarSiteProfile.get_current_profile(force=force)
-PARSE_FORMULA = re.compile(r"{([^}^\:]*)(?::.*)?}")
+PARSE_FORMULA = re.compile(r"{([^}^\\:]*)(?::[^}]*)?}")
PARSE_JINJA = re.compile("{{([^}]*)}")
PARSE_JINJA_IF = re.compile("{% if ([^}]*)}")