From fb1c985f31227afeaa3d3f97c9973e05924f3205 Mon Sep 17 00:00:00 2001 From: Swann Date: Mon, 17 May 2021 17:35:34 +0200 Subject: [PATCH] feat: node sanitize on collection and scene update --- multi_user/bl_types/bl_datablock.py | 24 ++++++++++-------------- multi_user/operators.py | 12 +++++++----- multi_user/timers.py | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/multi_user/bl_types/bl_datablock.py b/multi_user/bl_types/bl_datablock.py index 7cdb2d1..78a9844 100644 --- a/multi_user/bl_types/bl_datablock.py +++ b/multi_user/bl_types/bl_datablock.py @@ -133,21 +133,17 @@ class BlDatablock(ReplicatedDatablock): if not datablock_ref: try: datablock_ref = datablock_root[self.data['name']] - except Exception: - pass + except KeyError as e: + if construct: + name = self.data.get('name') + logging.debug(f"Constructing {name}") + datablock_ref = self._construct(data=self.data) + setattr(datablock_ref, 'uuid', self.uuid) + else: + return False + self.instance = datablock_ref + return True - if construct and not datablock_ref: - name = self.data.get('name') - logging.debug(f"Constructing {name}") - datablock_ref = self._construct(data=self.data) - - if datablock_ref is not None: - setattr(datablock_ref, 'uuid', self.uuid) - self.instance = datablock_ref - return True - else: - return False - def remove_instance(self): """ diff --git a/multi_user/operators.py b/multi_user/operators.py index f49b94a..b624676 100644 --- a/multi_user/operators.py +++ b/multi_user/operators.py @@ -946,7 +946,8 @@ def sanitize_deps_graph(remove_nodes: bool = False): rm_cpt += 1 except NonAuthorizedOperationError: continue - logging.info(f"Sanitize took { utils.current_milli_time()-start} ms, removed {rm_cpt} nodes") + if rm_cpt: + logging.info(f"Sanitize took { utils.current_milli_time()-start} ms, removed {rm_cpt} nodes") @persistent @@ -1013,14 +1014,15 @@ def depsgraph_evaluation(scene): # A new scene is created elif isinstance(update.id, bpy.types.Scene): ref = session.repository.get_node_by_datablock(update.id) - if ref: - ref.resolve() + if ref and ref.resolve(construct=False): + sanitize_deps_graph(remove_nodes=True) else: scn_uuid = porcelain.add(session.repository, update.id) porcelain.commit(session.node_id, scn_uuid) session.push(scn_uuid, check_data=False) - elif isinstance(update.id, bpy.types.Collection): - sanitize_deps_graph() + if isinstance(update.id, bpy.types.Collection): + sanitize_deps_graph(remove_nodes=True) + def register(): from bpy.utils import register_class diff --git a/multi_user/timers.py b/multi_user/timers.py index f414a2e..d088a77 100644 --- a/multi_user/timers.py +++ b/multi_user/timers.py @@ -248,7 +248,7 @@ class DynamicRightSelectTimer(Timer): key, RP_COMMON, ignore_warnings=True, - affect_dependencies=recursive) + affect_dependencies=True) except NonAuthorizedOperationError: logging.warning( f"Not authorized to change {key} owner")