diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-28 14:50:12 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-28 14:50:12 +0200 |
commit | 3eee5bac1748181d41d7abc32da1570a1fce6645 (patch) | |
tree | 2f2f39dfb5c185d8e8857b2f87bbeff6065bb321 /ishtar_common/utils.py | |
parent | f1366d27a7ccfcd2745aa0854f217941f6b2198c (diff) | |
download | Ishtar-3eee5bac1748181d41d7abc32da1570a1fce6645.tar.bz2 Ishtar-3eee5bac1748181d41d7abc32da1570a1fce6645.zip |
Better management of cascade updates
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index a2fdd36f3..f3df5c282 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -419,6 +419,11 @@ EXTRA_KWARGS_TRIGGER = [ ] +def cached_label_and_geo_changed(sender, **kwargs): + cached_label_changed(sender=sender, **kwargs) + post_save_geo(sender=sender, **kwargs) + + def cached_label_changed(sender, **kwargs): if not kwargs.get('instance'): return @@ -454,11 +459,13 @@ def _cached_label_changed(sender, **kwargs): return force_update = kwargs.get('force_update', False) + if hasattr(instance, "need_update") and instance.need_update: + force_update = True + instance.skip_history_when_saving = True + if not force_update and getattr(instance, '_cached_label_checked', False): return - force_update = kwargs.get('force_update', False) - if hasattr(instance, "refresh_cache"): instance.refresh_cache() @@ -475,12 +482,19 @@ def _cached_label_changed(sender, **kwargs): if lbl != getattr(instance, cached_label): changed.append((cached_label, lbl)) setattr(instance, cached_label, lbl) # update for cache + + if hasattr(instance, "need_update") and instance.need_update: + changed.append(("need_update", False)) + instance.need_update = False + if changed: instance._search_updated = False 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 (changed or not cached_labels) and hasattr(instance, "cascade_update"): + instance.cascade_update() updated = False if force_update or hasattr(instance, 'update_search_vector'): updated = instance.update_search_vector() @@ -837,11 +851,17 @@ def _post_save_geo(sender, **kwargs): instance.point_source = None modified = True + if hasattr(instance, "need_update") and instance.need_update: + instance.need_update = False + modified = True + if modified: instance.skip_history_when_saving = True instance._post_saved_geo = True instance._cached_label_checked = False instance.save() + if hasattr(instance, "cascade_update"): + instance.cascade_update() cache_key, __ = get_cache( sender, ["post_save_geo", instance.pk] ) |