From 14e2c9e6dd12f930f156cfedce2b984fc08c0def Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 8 Apr 2026 11:15:25 +0200 Subject: WIP --- ishtar_common/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index cb6511d9d..2135af3a6 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -2395,6 +2395,22 @@ def get_m2m_values(obj): return hist_values +def update_cached_hierarchy(obj): + updates = {} + for attr in obj.CACHED_HIERARCHY: + # for each type get all hierarchy then eliminate duplicate + cached_attr = f"cached_hierarchy_{attr}" + values = list(sorted( + set(chain(*[ + v.get_label_hierarchy() for v in getattr(obj, attr).all() + ])) + )) + if values != getattr(obj, cached_attr): + updates[cached_attr] = values + if updates: + obj.__class__.objects.filter(pk=obj.pk).update(**updates) + + def manage_m2m(obj, kwargs): obj._queue = kwargs.get("queue", settings.CELERY_DEFAULT_QUEUE) hist_values = get_m2m_values(obj) -- cgit v1.2.3