From 986cd64c6d8c0ff1d9d27d8c5d647133ea65c6e2 Mon Sep 17 00:00:00 2001 From: Olivier Giniaux Date: Fri, 8 Jul 2022 21:36:22 +0200 Subject: [PATCH] Improve performance when adding / deleting / updating several assets at once --- Editor/AssetProcessor.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Editor/AssetProcessor.cs b/Editor/AssetProcessor.cs index fd1a563..87c3427 100644 --- a/Editor/AssetProcessor.cs +++ b/Editor/AssetProcessor.cs @@ -20,8 +20,11 @@ public static void Init() /// private static void OnUpdate() { - while (Actions.Count > 0) { - Actions.Dequeue()?.Invoke(); + if (Actions.Count > 0) { + while (Actions.Count > 0) { + Actions.Dequeue()?.Invoke(); + } + ProjectCurator.SaveDatabase(); } } @@ -35,7 +38,6 @@ static string[] OnWillSaveAssets(string[] paths) var removedAsset = ProjectCurator.RemoveAssetFromDatabase(path); ProjectCurator.AddAssetToDatabase(path, removedAsset?.referencers); } - ProjectCurator.SaveDatabase(); }); } return paths; @@ -46,7 +48,6 @@ static void OnWillCreateAsset(string assetName) if (ProjectCuratorData.IsUpToDate) { Actions.Enqueue(() => { ProjectCurator.AddAssetToDatabase(assetName); - ProjectCurator.SaveDatabase(); }); } } @@ -54,8 +55,9 @@ static void OnWillCreateAsset(string assetName) static AssetDeleteResult OnWillDeleteAsset(string assetName, RemoveAssetOptions removeAssetOptions) { if (ProjectCuratorData.IsUpToDate) { - ProjectCurator.RemoveAssetFromDatabase(assetName); - ProjectCurator.SaveDatabase(); + Actions.Enqueue(() => { + ProjectCurator.RemoveAssetFromDatabase(assetName); + }); } return AssetDeleteResult.DidNotDelete; } @@ -66,7 +68,6 @@ static AssetMoveResult OnWillMoveAsset(string sourcePath, string destinationPath Actions.Enqueue(() => { ProjectCurator.RemoveAssetFromDatabase(sourcePath); ProjectCurator.AddAssetToDatabase(destinationPath); - ProjectCurator.SaveDatabase(); }); } return AssetMoveResult.DidNotMove;