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
Showing only changes of commit a88d77e6d3 - Show all commits

View File

@ -71,7 +71,9 @@ class AssetPipeline(bpy.types.PropertyGroup):
@property
def asset_collection(self):
return bpy.data.collections.get(self.asset_collection_name)
return bpy.data.collections.get(self.asset_collection_name) or bpy.data.collections.get(
self.asset_collection_name + "." + constants.LOCAL_SUFFIX
)
@asset_collection.setter
def asset_collection(self, coll):
@ -165,6 +167,19 @@ class AssetPipeline(bpy.types.PropertyGroup):
)
@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']
classes = (
AssetTransferData,
AssetTransferDataTemp,
@ -182,6 +197,7 @@ def register():
bpy.types.ID.asset_id_surrender = bpy.props.BoolProperty(
name="Surrender Ownership", default=False
)
bpy.app.handlers.load_post.append(AssetPipeline.set_asset_collection_name_post_file_load)
def unregister():
@ -190,3 +206,4 @@ def unregister():
del bpy.types.Object.transfer_data_ownership
del bpy.types.Scene.asset_pipeline
del bpy.types.ID.asset_id_owner
bpy.app.handlers.load_post.remove(AssetPipeline.set_asset_collection_name_post_file_load)