diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-08 11:15:25 +0200 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-08 11:15:25 +0200 |
| commit | 14e2c9e6dd12f930f156cfedce2b984fc08c0def (patch) | |
| tree | 8fe7cd5f5368665fed48831874c6bb24d16f7930 | |
| parent | 22896b4525fd218d828db01dcd28439dc1a56dc9 (diff) | |
| download | Ishtar-14e2c9e6dd12f930f156cfedce2b984fc08c0def.tar.bz2 Ishtar-14e2c9e6dd12f930f156cfedce2b984fc08c0def.zip | |
WIPdevelop-5.0
| -rw-r--r-- | ishtar_common/utils.py | 16 | ||||
| -rw-r--r-- | ishtar_common/views_item.py | 19 |
2 files changed, 34 insertions, 1 deletions
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) diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 94f8489ed..cac99f53f 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -95,6 +95,10 @@ ENCODING = settings.ENCODING or "utf-8" HIERARCHIC_LEVELS = 5 +HIERARCHIC_CACHED_FIELDS = ( + "material_types", +) + LIST_FIELDS = { # key: hierarchic depth "conservatory_states": HIERARCHIC_LEVELS, "identifications": HIERARCHIC_LEVELS, @@ -1568,6 +1572,14 @@ def _manage_hierarchic_fields(model, dct, and_reqs): req = req[: -(len(base_suffix))] + suffix else: current_values = [val] + if k_hr in HIERARCHIC_CACHED_FIELDS: + cached_key = f"cached_hierarchy_{k_hr}__contains" + for idx, nval in enumerate(current_values): + if not reqs: + reqs = Q(**{cached_key: [nval.upper()]}) + else: + reqs |= Q(**{cached_key: [nval.upper()]}) + continue new_req = None for idx, nval in enumerate(current_values): @@ -2915,6 +2927,8 @@ def get_item( search_vector = request_items.get("search_vector", "").strip() + print("OKOK1") + n = datetime.datetime.now() # cache only for GUI search cache_search = search_vector or any( 1 for k in request_items if k.startswith("columns[")) @@ -2945,7 +2959,10 @@ def get_item( if count: return items_nb - # print(str(items.values("id").query)) + print(2, datetime.datetime.now() - n) + n = datetime.datetime.now() + + print(str(items.values("id").query)) if data_type == "json-stats": stats_sum_variable = request_items.get("stats_sum_variable", None) |
