From 42054c7989b310a551665a4e26eabc734235e27e Mon Sep 17 00:00:00 2001 From: Bai Date: Wed, 24 Apr 2024 18:03:19 +0800 Subject: [PATCH] feat: Support asset tree node drag to another one --- apps/assets/api/node.py | 2 ++ apps/common/decorators.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/assets/api/node.py b/apps/assets/api/node.py index 30c533179..a8d852221 100644 --- a/apps/assets/api/node.py +++ b/apps/assets/api/node.py @@ -22,6 +22,7 @@ from orgs.utils import current_org from rbac.permissions import RBACPermission from .. import serializers from ..models import Node +from ..signal_handlers import update_nodes_assets_amount from ..tasks import ( update_node_assets_hardware_info_manual, test_node_assets_connectivity_manual, @@ -94,6 +95,7 @@ class NodeAddChildrenApi(generics.UpdateAPIView): children = Node.objects.filter(id__in=node_ids) for node in children: node.parent = instance + update_nodes_assets_amount.delay(ttl=5, node_ids=(instance.id,)) return Response("OK") diff --git a/apps/common/decorators.py b/apps/common/decorators.py index 65a9cad07..394b4ec15 100644 --- a/apps/common/decorators.py +++ b/apps/common/decorators.py @@ -204,6 +204,8 @@ def merge_delay_run(ttl=5, key=None): def delay(func, *args, **kwargs): from orgs.utils import get_current_org + # 每次调用 delay 时可以指定本次调用的 ttl + current_ttl = kwargs.pop('ttl', ttl) suffix_key_func = key if key else default_suffix_key org = get_current_org() func_name = f'{func.__module__}_{func.__name__}' @@ -220,7 +222,7 @@ def merge_delay_run(ttl=5, key=None): else: cache_kwargs[k] = cache_kwargs[k].union(v) _loop_debouncer_func_args_cache[cache_key] = cache_kwargs - run_debouncer_func(cache_key, org, ttl, func, *args, **cache_kwargs) + run_debouncer_func(cache_key, org, current_ttl, func, *args, **cache_kwargs) def apply(func, sync=False, *args, **kwargs): if sync: