Asset Pipeline: Use a weak ref for Asset Collection to improve performance #213

Merged
Nick Alberelli merged 3 commits from TinyNick/blender-studio-pipeline:fix/asset-collection-as-string into main 2024-01-25 17:06:04 +01:00
Member

What's Changed

  • Let's use a weak ref for now because this causes the collection to evaluate even when hidden, causing performance nightmares

Breaking Changes

  • This will reset the asset collection pointer on all files, this property will need to be re-set
## What's Changed - Let's use a weak ref for now because this causes the collection to evaluate even when hidden, causing performance nightmares ## Breaking Changes - This will reset the asset collection pointer on all files, this property will need to be re-set
Nick Alberelli added 1 commit 2024-01-24 18:34:31 +01:00
Nick Alberelli requested review from Demeter Dzadik 2024-01-24 18:35:04 +01:00
Author
Member

@Mets Feel free to squash commit if you want this rolled out asap, but be aware how this can break files

@Mets Feel free to squash commit if you want this rolled out asap, but be aware how this can break files
Demeter Dzadik requested changes 2024-01-25 00:27:27 +01:00
Demeter Dzadik left a comment
Member

How about adding this load_post handler to version old files?
Without this, the pointers would stick around anyways.

How about adding this load_post handler to version old files? Without this, the pointers would stick around anyways.
@ -74,3 +82,4 @@
default="",
description="Top Level Collection of the Asset, all other collections of the asset will be children of this collection",
)
Member
    @staticmethod
    @bpy.app.handlers.persistent
    def set_asset_collection_name_post_file_load(_):
        # Version the PointerProperty to the StringProperty, and the left-over pointer.
        for scene in bpy.data.scenes:
            if 'asset_collection' not in scene.asset_pipeline:
                continue
            coll = scene.asset_pipeline['asset_collection']
            if coll:
                scene.asset_pipeline.asset_collection_name = coll.name
                del scene.asset_pipeline['asset_collection']
```python @staticmethod @bpy.app.handlers.persistent def set_asset_collection_name_post_file_load(_): # Version the PointerProperty to the StringProperty, and the left-over pointer. for scene in bpy.data.scenes: if 'asset_collection' not in scene.asset_pipeline: continue coll = scene.asset_pipeline['asset_collection'] if coll: scene.asset_pipeline.asset_collection_name = coll.name del scene.asset_pipeline['asset_collection'] ```
TinyNick marked this conversation as resolved
@ -167,9 +176,7 @@ classes = (
def register():
Member

bpy.app.handlers.load_post.append(AssetPipeline.set_asset_collection_name_post_file_load)
...
bpy.app.handlers.load_post.remove(AssetPipeline.set_asset_collection_name_post_file_load)

` bpy.app.handlers.load_post.append(AssetPipeline.set_asset_collection_name_post_file_load)` ... ` bpy.app.handlers.load_post.remove(AssetPipeline.set_asset_collection_name_post_file_load)`
TinyNick marked this conversation as resolved
Demeter Dzadik reviewed 2024-01-25 01:44:24 +01:00
@ -73,0 +71,4 @@
@property
def asset_collection(self):
return bpy.data.collections.get(self.asset_collection_name)
Member

This also needs a tweak to not return None during pull, since we are actually renaming the asset collection before transfer.

from constants import LOCAL_SUFFIX
........
return bpy.data.collections.get(self.asset_collection_name) or bpy.data.collections.get(self.asset_collection_name + ".LOC")
This also needs a tweak to not return None during pull, since we are actually renaming the asset collection before transfer. ```python from constants import LOCAL_SUFFIX ........ return bpy.data.collections.get(self.asset_collection_name) or bpy.data.collections.get(self.asset_collection_name + ".LOC") ```
TinyNick marked this conversation as resolved
Nick Alberelli added 1 commit 2024-01-25 16:42:20 +01:00
Co-authored-by: Demeter Dzadik <demeter@blender.org>
Nick Alberelli added 1 commit 2024-01-25 17:00:12 +01:00
Co-authored-by: Demeter Dzadik <demeter@blender.org>
Nick Alberelli merged commit ad92d3c56e into main 2024-01-25 17:06:04 +01:00
Nick Alberelli deleted branch fix/asset-collection-as-string 2024-01-25 17:06:07 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: studio/blender-studio-tools#213
No description provided.